Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

layout manager question

 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still working on my applet. It is looking better, except I am having this one weird problem. I am trying to get two textfields for user input to display on the same line at the top of the browser window. The code I have makes them display as two small boxes. How do I make them longer? I don't know if this is a question of using the right layout manager, or what. Any input would be helpful. I am holding off on coding the action event methods until I can get the GUI to look somewhat presentable.
<code>
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class NumerologyApplet extends Applet

implements ActionListener {
//Declare the textfields for input
private TextField dateInput = new TextField("");
private TextField nameInput = new TextField("");
private TextArea results = new TextArea("");
//Declare buttons
private Button closeBtn = new Button("Close");
private Button compBtn = new Button("Compute");
private Button refBtn = new Button("Refresh");
//Declare panels

Panel xPanel = new Panel();
Panel yPanel = new Panel();
Panel zPanel = new Panel();
Panel buttonPanel = new Panel();
public void init() {
//Make sure textfield background is white
dateInput.setBackground(Color.white);
nameInput.setBackground(Color.white);
//Add textfields to panels

xPanel.add(dateInput);
yPanel.add(nameInput);
zPanel.add(results);
//Set layout for panels


//Add buttons to button panel
closeBtn.addActionListener(this);
buttonPanel.add(closeBtn);
compBtn.addActionListener(this);
buttonPanel.add(compBtn);
refBtn.addActionListener(this);
buttonPanel.add(refBtn);
//Add the panels
add(xPanel);
add(yPanel);
add(zPanel);
add(buttonPanel);
}
public void actionPerformed(ActionEvent event) {
}
}
</code>
 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When in doubt, go to the API JavaDocs
TextField has a constructor that takes the number of columns.
Junilu
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic