• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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

0
IncubusJax
Asked:
IncubusJax
1 Solution
 
ksivananthCommented:
0
 
IncubusJaxAuthor Commented:
Perfect thanks a million.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now