Link to home
Start Free TrialLog in
Avatar of IncubusJax
IncubusJax

asked on

Java formatting

Hi Everyone,

I have a program that I have listed in the code below that has a label and a couple of buttons. The problem is I can't remember how to format it. I want the buttons to align on the right side, the Exit centered at the bottom, and the date's label below that. On the left side I'd like to place a graphic.

Does anyone know who to do this or can point me to a tutorial?

Many thanks!
Mark
//I haven't began to "clean this up" at all, so things are wacky that's why.
 
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
 
import java.awt.event.*;
import java.awt.*;
import java.util.Date;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
 
 
@SuppressWarnings("serial")
public class General extends JFrame
{
	private JFrame mainFrame;
	private JButton cmdExit;
	private JLabel labelDate;
	private JButton Home;
	private JButton HotTubs;
	private JButton Pools;
	private JButton TempCalc;
		
	@SuppressWarnings("deprecation")
	public General()//default constructor
	{
		//Date
		SimpleDateFormat SDF;
		SDF = new SimpleDateFormat("MMMM dd, yyyy");
		TimeZone local = TimeZone.getDefault();
		SDF.setTimeZone(local);
		String dateString = SDF.format(new Date() );
		String date = dateString;
		
		mainFrame = new JFrame("");
		
		Home = new JButton("Home");
		HotTubs = new JButton("Hot Tubs");
		Pools = new JButton("Pools");
		TempCalc = new JButton("Temp Calc");
		cmdExit = new JButton("Exit");
		labelDate = new JLabel ("Today's Date is: " + date);
		
		Container c = mainFrame.getContentPane();
		
		c.setLayout(new FlowLayout());
		c.add(cmdExit);
		c.add(labelDate);
		c.add(HotTubs);
		c.add(Pools);
		c.add(TempCalc);
		c.add(Home);
		
		cmdExit.setMnemonic('E');
		HotTubs.setMnemonic('B');
		Pools.setMnemonic('P');
		TempCalc.setMnemonic('T');
		Home.setMnemonic('H');
		
		
		mainFrame.setSize(800,600);
		
		mainFrame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent E){System.exit(0);}
		});
		
		ButtonsHandler bhandler = new ButtonsHandler();
		cmdExit.addActionListener(bhandler);
		Home.addActionListener(bhandler);
		Pools.addActionListener(bhandler);
		HotTubs.addActionListener(bhandler);
		TempCalc.addActionListener(bhandler);
		
		mainFrame.show();
	}
	
	class ButtonsHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			if(e.getSource() == cmdExit)
				System.exit(0);
			if(e.getSource() == Home)
				System.exit(0);
			if(e.getSource() == HotTubs)
				new HotTubs();
			if(e.getSource() == Pools)
				new poolCalc();
			if(e.getSource() == TempCalc)
				System.exit(0);
		}
	}
	public static void main(String[] args)
		{
			@SuppressWarnings("unused")
			General app;
			app = new General();
		}
		
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IncubusJax
IncubusJax

ASKER

Perfect thanks a million.