【发布时间】:2015-03-07 03:13:40
【问题描述】:
我想通过点击一个按钮来调用另一个小程序;然后旧的小程序将被关闭或重新加载到新的小程序。
我的动作监听器还没有任何东西。
public class ConImage extends JApplet implements ActionListener {
Button btn;
Applet second;
public void init()
{
setSize(1600,900);
setLayout(null);
btn=new Button("Replace with other applet");
add(btn);
btn.addActionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
btn.setLocation(100, 100);
btn.setSize(100, 50);
}
public void actionPerformed(ActionEvent e)
{ second=null;
second= getAppletContext().getApplet("SecondClass");
if (second!=null)
{
if(e.getSource()==Time)
{
SecondClass ma= (SecondClass) second;
}
}
}
}
【问题讨论】:
-
请不要以大写开头的变量名
-
我认为这是不可能的,因为 Java 的安全功能。
-
使用 CardLayout 在视图之间切换
-
我已经删除了所有只会影响您的问题重点的附带细节。
-
感谢大家的建议,我会尽力改进。我只是这方面的新手,我只是通过教程学习