User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,041 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2302 | Replies: 31 | Solved
Reply
Join Date: Oct 2007
Posts: 36
Reputation: babyfrostie is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
babyfrostie babyfrostie is offline Offline
Light Poster

need help with the GUI

  #1  
Oct 11th, 2007
need help with the GUI of my program...
i want it to be like this:
http://img256.imageshack.us/img256/8919/faceeq9.th.jpg
but this is what it shows.. hehe
http://img440.imageshack.us/img440/8486/caym9.th.jpg

im having a hard time with the GridLayout coz i think ie. GridLayout 3,4 doesnt appear to be 3,4..

thankss...
import java.awt.*;
import java.awt.event.*;

public class Project extends Frame implements ActionListener {

		private TextArea display;
		private TextArea msg;
		
	public static void main (String args[]){
		Project cl = new Project();
		FlowLayout fl = new FlowLayout();
		Panel panel1 = new Panel();
		Panel panel2 = new Panel();
		Panel panel3 = new Panel();
		Panel panel4 = new Panel();
		Panel panel5 = new Panel();
		GridLayout gl = new GridLayout(1,3);
		Button quit = new Button("Quit");
		Button print = new Button("Print Total");
		
		TextArea display = new TextArea("Information");
		TextField msg = new TextField("%");
		
		cl.setSize(650,500); // window size
		cl.setLayout(new BorderLayout());

		// PANEL 1
		panel1.add(new Label ("Cash Register for Carinderias :)"));
		
	    // PANEL 2 
	    panel2.setLayout(new GridLayout(10,0));
	    panel2.setSize(450,600);
	    panel2.add(new Label("Rice"));
	    panel2.add(new Label("Softdrinks"));
	    panel2.add(new Label("Meat"));
	    panel2.add(new Label("Soup"));
	    panel2.add(new Label("Arroz Caldo"));
	    panel2.add(new Label("Batchoy"));
		//List list = new List (5, false); //list of items
	      //list.add ("Rice");
	      //list.add ("Softdrinks (8oz)");
	      //list.add ("Meat");
	     // list.add ("Soup");
	     // list.add ("Arroz Caldo");
	   // panel2.add(list);
	   //panel2.setLayout(new GridLayout(10,0));
		msg.setBackground(Color.GREEN);
		panel2.add(new Label("How many percent discount?"));
		panel2.add(msg);
     	panel2.add(new Button ("Give Discount"));
		
		// PANEL 3 
		Choice choose = new Choice();
		choose.add("Dine In");
		choose.add("Take Out");
		panel3.add(choose);
		//panel3.add(new Checkbox("Dine in"));
		//panel3.add(new Checkbox("Take out"));
		panel3.add(print);
		
		// PANEL 4
		//panel4.add(new TextArea("Information"));
		display.setBackground(Color.YELLOW);
		panel4.add(display);
		
		// PANEL 5 
		panel5.add(new Button ("Next"), BorderLayout.CENTER);
		panel5.add(quit);
		quit.addActionListener(this);
		
		// the GridLayout consist of Panels
		cl.setLayout(new GridLayout(5,5));
		cl.add(panel1, BorderLayout.NORTH);
		cl.add(panel2, BorderLayout.CENTER);
		cl.add(panel3, BorderLayout.CENTER);
		cl.add(panel4, BorderLayout.CENTER);
		cl.add(panel5, BorderLayout.SOUTH);
		cl.setTitle("Cash Register");
		cl.setVisible(true);

	}

	// Prints the total in the display window
	public void actionPerformed(ActionEvent e)
	{
		if ("Print Total".equals(e.getActionCommand()))
		{
		String myText="";
		myText=msg.getText();
		display.append(myText);
		
	    if ("Quit".equals(e.getActionCommand()))
		{
			System.exit(0);
		}
		}
	}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: in a dream
Posts: 127
Reputation: nschessnerd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 6
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Junior Poster

Re: need help with the GUI

  #2  
Oct 12th, 2007
can you make those photos larger?
this.love(*);
&hea/rts;
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 311
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: need help with the GUI

  #3  
Oct 12th, 2007
Originally Posted by nschessnerd View Post
can you make those photos larger?

No need for it, if you will try that program you would understand what he is about....


GridLayout is not best solution for the layout you try to do. You should consider BoxLayout, GridBagLayout or combination of more then one. So if we look at first image you can split it on 3 main sections
  1. Labels, text fields, combobox and buttons in top part
  2. Text area from middle
  3. Two buttons from bottom

Then top part can be split on following
  • 3 text fields with their labels from left
  • text field with label from middle together with combo box(this can be also split but not necessary)
  • 2 buttons from the right

Hope that helps
Last edited by peter_budo : Oct 12th, 2007 at 8:25 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Oct 2007
Posts: 36
Reputation: babyfrostie is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
babyfrostie babyfrostie is offline Offline
Light Poster

Re: need help with the GUI

  #4  
Oct 12th, 2007
I didnt know that BoxLayout and GridBagLayout exists... Hehe ill try that.. thanks!! it really helped me..
Reply With Quote  
Join Date: Oct 2007
Posts: 36
Reputation: babyfrostie is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
babyfrostie babyfrostie is offline Offline
Light Poster

GUI done...

  #5  
Oct 15th, 2007
Im done with the simple GUI with the help of GridBagLayout... thanks guys..

Output: http://img98.imageshack.us/img98/5559/fnlgg8.th.jpg
import java.awt.*;
import java.awt.event.*;


public class testing extends Frame
{
	private Label rice = new Label("Rice --- P10/cup");
	private TextField rice1 = new TextField("");
	private Label egg = new Label("Egg --- P15");
	private TextField egg1 = new TextField("");
	private Label softdrink = new Label("Softdrink --- P15");
	private TextField softdrink1 = new TextField("");
	private Label tapsilog = new Label("Tapsilog --- P15");
	private TextField tapsilog1 = new TextField("");
	private Label cornedbeef = new Label("Corned Beef --- P25");
	private TextField cornedbeef1 = new TextField("");
	private Label chopsuey = new Label("Chopsuey --- P20");
	private TextField chopsuey1 = new TextField("");
	
	private Label discount = new Label("Discount:");
	private TextField discount1 = new TextField("");
	private Button givediscount = new Button("Give Discount");
	
	private Button print = new Button("Print");
	private Button quit = new Button("Quit");
	private Button next = new Button("Next");
	
	private TextArea output = new TextArea("",15,25);
	
	public testing()
 {
  super( "Cash Register" );
  GridBagLayout gridbag = new GridBagLayout();
  GridBagConstraints c = new GridBagConstraints();
  setLayout( gridbag );
  c.weightx = 0;
  c.weighty = 0;
  c.ipadx = 2;

  // Rice
  c.gridx = 0;
  c.gridy = 1;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( rice, c );
  add( rice );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( rice1, c );
  add( rice1 );

  // Egg
  c.gridx = 0;
  c.gridy = 2;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( egg, c );
  add( egg );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( egg1, c );
  add( egg1 );

  // Softdrink
  c.gridx = 0;
  c.gridy = 3;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( softdrink, c );
  add( softdrink );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( softdrink1, c );
  add( softdrink1 );

  // tapsilog
  c.gridx = 0;
  c.gridy = 4;
  c.anchor = GridBagConstraints.NORTHEAST;
  gridbag.setConstraints( tapsilog, c );
  add( tapsilog );
  c.gridx = 1;
  c.anchor = GridBagConstraints.NORTHWEST;
  gridbag.setConstraints( tapsilog1, c );
  add( tapsilog1 );
  
  // corned beef
  c.gridx = 0;
  c.gridy = 5;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( cornedbeef, c );
  add( cornedbeef );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( cornedbeef1, c );
  add( cornedbeef1 );

  // chopsuey
  c.gridx = 0;
  c.gridy = 6;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( chopsuey, c );
  add( chopsuey );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( chopsuey1, c );
  add( chopsuey1 );
  
 // dine in or take out
  c.gridx = 0;
  c.gridy = 7;
  c.anchor = GridBagConstraints.EAST;
  Choice dinein = new Choice();
  dinein.add("Dine In");
  dinein.add("Take Out");
  gridbag.setConstraints( dinein, c );
  add( dinein );
 

  // discount
  c.gridx = 0;
  c.gridy = 8;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( discount, c );
  add( discount );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( discount1, c );
  add( discount1 );
  c.gridx = 2;
  c.anchor = GridBagConstraints.CENTER;
  gridbag.setConstraints( givediscount, c );
  add( givediscount );
  
  // output and print
  c.gridx = 0;
  c.gridy = 9;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( output, c );
  add( output );
  c.gridx = 3;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( print, c );
  add( print );
  
  // next and quit
  c.gridx = 0;
  c.gridy = 10;
  c.anchor = GridBagConstraints.EAST;
  gridbag.setConstraints( next, c );
  add( next );
  c.gridx = 1;
  c.anchor = GridBagConstraints.WEST;
  gridbag.setConstraints( quit, c );
  add( quit );
  
  this.setLocation( 100, 100 );
  this.setSize( 500, 500 );
  this.setVisible( true );
 }
 
 public static void main (String args[]) {
 	testing test = new testing();
 	
 	test.addWindowListener
            (new WindowAdapter()
                {
                    public void windowClosing (WindowEvent e)
                    {
                        System.exit (0);
                    }
 });
 }
 
}
another question: im going to put something in all the text field... how can i transfer them(text field items) to the TextArea(output) by clicking the PRINT button?

Similar to this:
http://img528.imageshack.us/img528/5...condug1.th.jpg

oh, can i put labels in the TextArea? or a table??
Last edited by babyfrostie : Oct 15th, 2007 at 11:09 am.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 311
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: need help with the GUI

  #6  
Oct 15th, 2007
You have to associate apropriate action with your Print button which will retrive all data from labels and text fields, then display them in text area

To collect your data use following methods
JTextField.getText() - will return string inside text component. The method is inherited from JTextComponent
JLabel.getText() - returns the text string that the label displays.

PS: Next time you realy need to give bigger images or provide binoculars to see these miniatures
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Oct 2007
Posts: 36
Reputation: babyfrostie is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
babyfrostie babyfrostie is offline Offline
Light Poster

Re: need help with the GUI

  #7  
Oct 15th, 2007
the output of my simple GUI

woops.. i copied the wrong link hehe sorry..

similar to what i want to happen
Last edited by babyfrostie : Oct 15th, 2007 at 1:48 pm.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 311
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: need help with the GUI

  #8  
Oct 15th, 2007
Above commands are what you need to use...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Oct 2007
Posts: 36
Reputation: babyfrostie is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
babyfrostie babyfrostie is offline Offline
Light Poster

Re: need help with the GUI

  #9  
Oct 15th, 2007
waa.. i dont know understand about public String getText()...
can you give me a sample of it??

this is my action for the PRINT button:
 public void actionPerformed (ActionEvent e)
{
  if(e.getActionCommand()=="PRINT")
  {  String temp="";
      temp=rice1.getText();        
      output.append(temp);
      rice1.setText("");
  }
not working though
Last edited by babyfrostie : Oct 15th, 2007 at 2:41 pm.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: need help with the GUI

  #10  
Oct 15th, 2007
Originally Posted by babyfrostie View Post
waa.. i dont know understand about public String getText()...
can you give me a sample of it??

this is my action for the PRINT button:
 public void actionPerformed (ActionEvent e)
{
  if(e.getActionCommand()=="PRINT")
  {  String temp="";
      temp=rice1.getText();        
      output.append(temp);
      rice1.setText("");
  }
not working though
That's because your button says "Print", not "PRINT". Your check on the action command is failing because of that.
Another way to determine which component is making the call is to use e.getSource() and compare that to your components
  public void actionPerformed (ActionEvent e)
{
  if(e.getSource() == print)
  {  String temp="";
      temp=rice1.getText();        
      output.append(temp);
      rice1.setText("");
  }
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC