View Single Post
Old 04-21-2009, 01:14 PM   #1 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Anyone here knows Java?

Heya!
I don't know where to post this, so the Lounge it is!

Anyway, I have a problem with my Java script(not JavaScript - Java script), and I'm wondering if someone could help me out what the problem(s) is(/are)?

With syntax highlighting: http://pastebin.com/m4666a6ed
With no syntax highlighting:
Code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class GUI extends JFrame implements ActionListener
{
	
	private static final String FRAME_TITLE = "Bank";
	
	private static final int FRAME_WIDTH = 600;
	private static final int FRAME_HEIGHT = 400;
	
	private static final int FRAME_X_ORIGIN = 300;
	private static final int FRAME_Y_ORIGIN = 350;
	
	private JMenu fileMenu;
	private JMenuBar menuBar;
	
	private Container cont;
	
	private JTextField addCust_socNr;
	private JTextField addCust_name;
	private JButton addCust_add;
	
	public static void main(String[] args)
	{
		
		GUI frame = new GUI();
		frame.setVisible(true);
		
	}
	
	public GUI()
	{
		
		this.initiate();
		this.build();
		
	}
	
	public void initiate()
	{
		
		this.cont = this.getContentPane();
		this.menuBar = new JMenuBar();
		setJMenuBar(this.menuBar);
		
	}
	
	public void build()
	{
		
		this.buildFileMenu();
		
		this.setTitle(FRAME_TITLE);
		this.setSize(FRAME_WIDTH, FRAME_HEIGHT);
		this.setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
		this.setResizable(false);
		
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		
	}
	
	public void actionPerformed(ActionEvent event)
	{
		
		String option;
		
		option = event.getActionCommand();
		if(option.equals("Quit"))
		{
			
			System.exit(0);
			
		}
		
		else if(option.equals("New customer"))
		{
			
			this.addCustomer();
			
		}
		
		else if(option.equals("Import customer"))
		{
			
			JOptionPane.showMessageDialog(null, "This is not supported yet.");
			
		}
		
	}
	
	public void buildFileMenu()
	{
		
		this.fileMenu = new JMenu("File");
		
		
		JMenuItem newCustomer = new JMenuItem("New customer");
		newCustomer.addActionListener(this);
		
		JMenuItem openCustomer = new JMenuItem("Import customer");
		openCustomer.addActionListener(this);
		
		JMenuItem closeProgram = new JMenuItem("Quit");
		closeProgram.addActionListener(this);
		
		this.fileMenu.add(newCustomer);
		this.fileMenu.add(openCustomer);
		this.fileMenu.addSeparator();
		this.fileMenu.add(closeProgram);
		
		this.menuBar.add(this.fileMenu);
		
	}
	
	public void addCustomer()
	{
		
		this.cont.setLayout(new BorderLayout());
		
		
		JPanel mainContainer = new JPanel();
		mainContainer.setLayout(new GridLayout(2, 1));
		
		JPanel leftContainer = new JPanel();
		leftContainer.setLayout(new GridLayout(2, 1));
		
		
		this.addCust_socNr = new JTextField();
		this.addCust_socNr.setColumns(22);
		
		this.addCust_name = new JTextField();
		this.addCust_name.setColumns(22);
		
		this.addCust_add = new JButton("Add");
		this.addCust_add.addActionListener(this);
		
		mainContainer.add(this.addCust_socNr);
		mainContainer.add(this.addCust_name);
		leftContainer.add(this.addCust_add);
		
		this.cont.add(leftContainer, BorderLayout.WEST);
		this.cont.add(mainContainer, BorderLayout.CENTER);
		
	}
	
}
When I click "New customer" it should show a complete layout.. but it doesn't show anything. I tried just doing this.setTitle to change the title when I'm in addCustomer method - it works, so it gets directed to the method properly.. it just doesn't add the layout..

Anyone?
__________________
Tanax is offline  
Reply With Quote