Java Applet GUI 组件问题
我在将 GUI 组件放入小程序中时遇到问题。我正在寻找一种使用绝对坐标和尺寸放置它的方法。 这就是我所做的:
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);
}
}
我不知道该怎么做,要么组件不显示,要么它们适合整个小程序区域。我想为我的所有按钮、文本区域等指定它们的确切大小以及它们将放置的确切位置。我在网上查看了教程,但它不起作用,组件没有显示。
我也不希望按钮、文本区域等调整大小。我指示的一切都是静态的。例如,创建大小为 (15,35) 的 JTextArea 时;这似乎并不重要,因为它无论如何都会调整大小。
谢谢
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 placed. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用于
init()
中的小程序。use
for your applet in your
init()
.