有没有可能添加一个小程序(具体地说是JBufferedApplet)到一个JFrame (或一个AWT框架)。
我已经试过了,但是看起来小程序根本不能运行。它使JFrame的背景颜色变为灰色(与小程序的颜色相同),但仅此而已。
不可能将JApplet更改为JPanel (我无法访问代码)。
目前要做的就是将Applet添加到JFrame/AWT框架中
这是我到目前为止所拥有的代码:
import javax.swing.JFrame;
public class FormFrame extends JFrame {
public FormFrame() {
super("Oracle Forms");
Main m = new Main();
getContentPane().add(m); //add(m);
setSize(800, 600);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new FormFrame();
}
}
它给出的只是Applet的背景色。看起来小程序不能运行。
发布于 2012-03-27 22:39:10
您可以随时尝试添加小程序的contentPane,如下所示:
public class FormFrame extends JFrame {
public FormFrame() {
super("Oracle Forms");
MyApplet myApplet = new MyApplet();
myApplet.start();
myApplet.init();
getContentPane().add(myApplet.getContentPane());
setSize(800, 600); // not sure about this. Usually better to call pack();
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FormFrame();
}
});
}
}
但不要忘了调用小程序的init()
方法,以允许它初始化所有组件。
编辑:根据垃圾神的优秀建议,对线程安全进行了更改。
https://stackoverflow.com/questions/9891541
复制相似问题