Neil Guerin

Greenhorn
+ Follow
since Mar 16, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Neil Guerin

Have just tested this code you provided and it does exactly what I was looking for. Thank you so much for your help. Really appreciate it.
19 years ago
Hi. I'm trying to lay out panels in a test applet shown below. I want to have two panels each with a different layout manager. I want the first panel to always display above the other one when the applet is launched. At present, the second panel appears directly after the first panel. Is there anyway I can get around this so I can achieve the layout I want? I did get it working using the JApplet class but I don't like the look and feel of that -- I'm doing early gui testing for an applet to mimic a standard html web form for a college project and the Applet class is the one I have to use.
I also tried putting the two panels in a single container and applying a border layout to both panels when added to the container (north and south respectively). Although the file compiles, nothing displays in the Applet when I run the appletviewer when attempting that approach. It just says Applet initiated and remains a blank window).
Here is the source code for the one that does display but not the way I'd like: would really appreciate any tips or web references anybody can provide. I've looked at Sun's tutorials and my textbook but they all use JApplet examples although they do say it should be possible to position panels too as they are containers. Let me know if I have that wrong. Thanks for any help in advance.
//
// TESTING: MULTIPLE LAYOUTS USING PANELS COMBINED WITH APPLET CLASS NOT JAPPLET
//
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class NetApplet4 extends Applet
{
private TextField message = null ;
private Button button = null;
private TextField message2 = null ;
private Button button2 = null;
private boolean pressed = false;

// extra test variables
private Button button3 = null;
private TextField message3 = null;
private Button button4 = null;
private TextField message4 = null;
public NetApplet4()
{
}
public void init()
{
// set default window size
resize(750, 400);
// declare a new panel
Panel pnlDisplay1 = new Panel();

// assign a layout manager to the panel
pnlDisplay1.setLayout(new GridLayout(0,2));

// instantiate objects for panel 1
button = new Button("PRESS ME");
message = new TextField(30);
message.setEditable(false);
button3 = new Button("Button 3");
message3 = new TextField("Message 3");
button4 = new Button("Button 4");
message4 = new TextField("Message 4");
// add objects to panel 1
pnlDisplay1.add(button);
pnlDisplay1.add(message);
pnlDisplay1.add(button3);
pnlDisplay1.add(message3);
pnlDisplay1.add(button4);
pnlDisplay1.add(message4);

// add the panel1
add(pnlDisplay1, BorderLayout.NORTH);
// declare a new panel
Panel pnlDisplay2 = new Panel();

// assign a layout manager to the panel
pnlDisplay2.setLayout(new FlowLayout());
// instantiate objects for panel 2
button2 = new Button("Submit Ticket Order Online");
// add objects to panel 2
pnlDisplay2.add(button2);
// add the panel2
add(pnlDisplay2, BorderLayout.SOUTH);

}
} // end NetApplet4 class
19 years ago