嗨 stackoverflow 开发人员我必须在摇摆中设计一个有两个菜单的表单。onclicking 一个菜单我想在它上面添加一个 jinternal 框架。然后单击 jinternalframe 上的按钮后,应删除 jinternalframe 并应在 jframe 表单上添加新控件。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.event.*;
class MainMenu extends JFrame implements ActionListener
{
JMenuBar mb;
Menu field,test;
MainMenu()
{
Container cp=this.getContentPane();
mb= new JMenuBar();
field1= new JMenu("field1");
test=new JMenu("test");
mb.add(field1);
mb.add(test);
setJMenuBar(mb);
field1.addActionListener(this);
test.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("field1");
{
jinternalframe1 frm= new jinternalframe();
cp.add(frm);
frm.setBounds(0,0,600,600);
}
}
public static void main(String args[])
{
MainMenu frm = new MainMenu();
frm.setSize(1000,1000);
frm.setVisible(true);
}
}
public class jinternalframe1 extends JInternalFrame implements ActionListener
{
JButton jb1,jb2;
jinternalframe1()
{
jb1= new JButton("1");
jb2=new JButton("2");
add(jb1);
add(jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("1"))
{
JButton nn= new JButton("back");
MainMenu frm= new MainMenu();
frm.cp.add(nn);
//this is creating new Form but i want to add the new button control instead of add //jinternal frame
}
}
}