• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

organising panels

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to polish off my GUI but I have several problems:
1 - The initial screen has two buttons booking and quit. When the user click booking other buttons appears with labels and textbox. The problem I'm having is that these new buttons do not appear, I have to maximise the window for them to appear.

2 - I created several panels so that each textbox and labels appear underneath each other but that doesn't work as they appear a bit all over the place!
My code is the following:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class Jobs extends Panel implements ActionListener
{
private Button booking=new Button("make a booking");
private TextField staff=new TextField (10);
private TextField jbcode = new TextField(4);
private TextField Startdate = new TextField(6);
private TextField Enddate = new TextField(6);
private TextField jobs=new TextField(1);
private Label jobt=new Label("Enter the job type");
private Label id = new Label ("Enter your staff id");
private Label jobcode=new Label("Enter the code of your job");
private Panel position=new Panel();
private Panel staffid=new Panel();
private Panel codepanel=new Panel();
private Panel sub= new Panel();
private Panel sedate=new Panel();
private Panel jobtype=new Panel();
private Panel d=new Panel();
private Label type= new Label ("Choose productive or non productive to submit the details");
private Label date=new Label("Enter the startdate of your job (e.g.30/APR/03)");
private Label ndate=new Label("Enter the end date of your job (e.g.30/MAY/03)");
private Button quitbutton=new Button ("Quit the booking system");
private Button submit = new Button ("Submit your booking");
public Jobs (){

position.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
position.add(booking);
position.add(quitbutton);
add(position);
booking.addActionListener(this);
quitbutton.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{if (e.getSource() == booking)
{
staffid.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
staffid.add(staff);
staffid.add(id);
add(staffid);
codepanel.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
codepanel.add(jbcode);
codepanel.add(jobcode);
add(codepanel);
d.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
d.add(date);
d.add(Startdate);
add(d);
sedate.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
sedate.add(ndate);
sedate.add(Enddate);
add(sedate);
jobtype.setLayout(new FlowLayout(FlowLayout.LEFT,20,20));
jobtype.add(jobt);
jobtype.add(jobs);
add(jobtype);
sub.setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
sub.add(submit);
add(sub);
submit.addActionListener(this);
}
Could anyone tell me what I'm doing wrong?
Thank you very much!
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I might have missed it, but I did not see you call pack(). When you pack your JFrame or Frame, you let the layout manager do its job - that is, resize the container and paint the components onto it.
Add a call to frame.pack() and see if that does the trick.
 
Ariane Bogain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where should I put this call to frame pack? I've tried to put it like this:
import java.awt.*;
public class Log{
public static void main(String[] args)
{Frame frame=new Frame();
frame.pack();
frame.setTitle("Password");
Jobs test=new Jobs();
frame.setSize(700,700);
frame.setBackground(Color.lightGray);
frame.add(test);
frame.setVisible(true);

}
}
but I still have to maximise and minimise the window to have the new elements appearing!
 
reply
    Bookmark Topic Watch Topic
  • New Topic