开发者

Java Applet GUI problem with components

I'm having trouble with placing GUI components in an applet. I am looking for a way to place it using absolute coordinate and sizes. Here's what I've done:

public class app extends JApplet { 


public void init() {
    setSize(450,450);
    try {
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    } catch (Exception e) {
        System.err.println("Creation of swing components not finished");
    }


}

public void createGUI() {
    JMenuBar menubar = new JMenuBar();
    JMenu menuFile = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    menuFile.add(openItem);
    menubar.add(menuFile);
    setJMenuBar(menubar);


    app_buttons ab = new app_buttons();
    add(ab.button1);
    add(ab.button2);
    add(ab.button3);
}



}



public class app_buttons {
    public JButton button1;
    public JButton button2;
    public JButton button3;

    public apptextbox() {
       button1 = new JButton("1");
               button1.setBounds(20,20,20,20);
       button2 = new JButton("2");
               button2.setBounds(60,60,20,20);
       button3 = new JButton("3");
               button3.setBounds(90,90,20,20);

    }
 }

I can't figure out how to do it, either the components don't show or they fit the whole applet area. I want to specify for all my buttons, textareas, etc exactly how big they are and exactly where they will be pl开发者_如何学运维aced. I've looked at tutorials on the web but it dosn't work, the components dont get displayed.

I don't want buttons, textareas, etc to resize either. Everything just static where I indicate them. For example when creating a JTextArea with (15,35) in size; it dosn't seem to matter because it resizes anyway.

Thanks


use

setLayout(null);

for your applet in your init().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜