•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 0
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...
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);
}
}
}
}•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation:
Rep Power: 12
Solved Threads: 311
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
- Labels, text fields, combobox and buttons in top part
- Text area from middle
- 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
Publilius Syrus
(~100 BC)
LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
•
•
Join Date: Oct 2007
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 0
Im done with the simple GUI with the help of GridBagLayout... thanks guys..
Output: http://img98.imageshack.us/img98/5559/fnlgg8.th.jpg
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??
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);
}
});
}
}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.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation:
Rep Power: 12
Solved Threads: 311
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
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
•
•
Join Date: Oct 2007
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 0
the output of my simple GUI
woops.. i copied the wrong link hehe sorry..
similar to what i want to happen
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.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation:
Rep Power: 12
Solved Threads: 311
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
•
•
Join Date: Oct 2007
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 0
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:
not working though
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("");
}
Last edited by babyfrostie : Oct 15th, 2007 at 2:41 pm.
•
•
•
•
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:
not working thoughpublic void actionPerformed (ActionEvent e) { if(e.getActionCommand()=="PRINT") { String temp=""; temp=rice1.getText(); output.append(temp); rice1.setText(""); }
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("");
}![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How do I make a GUI in C++ (C++)
- GUI development in LINUX (Window and Desktop Managers)
- Project on offer - GUI for ATi Drivers (Software Development Job Offers)
- GUI Library help (C++)
- Help with gui loop. (C)
Other Threads in the Java Forum
- Previous Thread: SUN java Exam.....Need help
- Next Thread: odd numbers



Linear Mode