主题:[原创]大家帮我看看这个程序!!!!!
我想在点击每个菜单按钮时关闭原来窗体,新打开一个窗体,怎么改进代码,或者怎么实现????谢谢大家!!!!
package AnythingSet;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import JavaSwing.ComboBoxDemo;
/**
*
* @author Administrator
*
*/
public class ViewFrame extends Applet implements ActionListener
{
/**
* @serialField
*/
private static final long serialVersionUID = 1L;
private JFrame f;
private Panel flowPanel;
private Panel gridPanel;
private Panel flowPanel1;
private Panel boxPanel;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton b5;
public ViewFrame()
{
f=new JFrame("学生管理系统");
f.setSize(600,400);
f.setLocation(100,100);
f.setBackground(Color.gray);
Container contentPane=f.getContentPane();
contentPane.setLayout(new BorderLayout());
setPanel1();
setPanel2();
contentPane.add(flowPanel,"North");
contentPane.add(gridPanel,"Center");
f.setBackground(Color.BLUE);
f.setResizable(false);
f.setVisible(true);
}
public void exit()
{
f.addWindowListener(new WindowListener()
{
public void windowActivated(WindowEvent e)
{}
public void windowClosed(WindowEvent e)
{}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e)
{}
public void windowDeiconified(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void windowOpened(WindowEvent e)
{}
});
}
public void setPanel1()
{
flowPanel=new Panel();
flowPanel.setSize(600, 40);
Box box=Box.createHorizontalBox();
Font font=new Font("楷体_GB2312",Font.BOLD,40);
JLabel l;
l=new JLabel("学生管理系统(v1.1)");
l.setHorizontalTextPosition(JLabel.HEIGHT);
l.setFont(font);
box.add(l,Box.BOTTOM_ALIGNMENT);
flowPanel.add(box,Panel.CENTER_ALIGNMENT);
flowPanel.setBackground(Color.LIGHT_GRAY);
}
public void setPanel2()
{
gridPanel=new Panel();
gridPanel.setSize(600, 360);
gridPanel.setLayout(new GridLayout(1,2));
//Box baseBox1=Box.createHorizontalBox();
setFlowPanel();
setBoxPanel();
gridPanel.add(flowPanel1);
gridPanel.add(boxPanel);
//baseBox1.add(flowPanel1, Box.TOP_ALIGNMENT);
//baseBox1.add(Box.createHorizontalStrut(20));
//baseBox1.add(boxPanel,Box.LEFT_ALIGNMENT);
//gridPanel.add(baseBox1);
}
public void setFlowPanel()
{
flowPanel1=new Panel();
//flowPanel1.setSize(300, 300);
flowPanel1.setLayout(new BorderLayout());
JLabel l=new JLabel(new ImageIcon(".\\icon\\1.jpg"));
flowPanel1.add(l,"Center");
flowPanel1.setBackground(Color.blue);
}
public void setBoxPanel()
{
boxPanel=new Panel();
boxPanel.setSize(300,300);
boxPanel.setLocation(300,100);
boxPanel.setLayout(new BoxLayout(boxPanel,BoxLayout.X_AXIS));
Box baseBox=Box.createVerticalBox();
b1=new JButton(" 输入学生信息 ");
b2=new JButton(" 查询学生信息 ");
b3=new JButton(" 统计平均成绩 ");
b4=new JButton(" 统计总成绩 ");
b5=new JButton(" 关于我们 ");
JLabel ll=new JLabel(" ====功能菜单====");
baseBox.add(Box.createHorizontalStrut(1));
baseBox.add(ll);
baseBox.add(Box.createHorizontalStrut(1));
baseBox.add(b1);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b2);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b3);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b4);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b5);
baseBox.add(Box.createHorizontalStrut(1));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
JLabel l=new JLabel(" 科比工作室版权所有,盗版必究。");
//baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(l);
boxPanel.add(baseBox,Panel.TOP_ALIGNMENT);
flowPanel1.setBackground(Color.green);
}
public static void main(String[] args)
{
new ViewFrame();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
exit();
//new ComboBoxDemo();
}
if(e.getSource()==b2)
{
exit();
}
if(e.getSource()==b3)
{
exit();
}
if(e.getSource()==b4)
{
exit();
}
if(e.getSource()==b5)
{
exit();
}
}
}
package AnythingSet;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import JavaSwing.ComboBoxDemo;
/**
*
* @author Administrator
*
*/
public class ViewFrame extends Applet implements ActionListener
{
/**
* @serialField
*/
private static final long serialVersionUID = 1L;
private JFrame f;
private Panel flowPanel;
private Panel gridPanel;
private Panel flowPanel1;
private Panel boxPanel;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton b5;
public ViewFrame()
{
f=new JFrame("学生管理系统");
f.setSize(600,400);
f.setLocation(100,100);
f.setBackground(Color.gray);
Container contentPane=f.getContentPane();
contentPane.setLayout(new BorderLayout());
setPanel1();
setPanel2();
contentPane.add(flowPanel,"North");
contentPane.add(gridPanel,"Center");
f.setBackground(Color.BLUE);
f.setResizable(false);
f.setVisible(true);
}
public void exit()
{
f.addWindowListener(new WindowListener()
{
public void windowActivated(WindowEvent e)
{}
public void windowClosed(WindowEvent e)
{}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e)
{}
public void windowDeiconified(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void windowOpened(WindowEvent e)
{}
});
}
public void setPanel1()
{
flowPanel=new Panel();
flowPanel.setSize(600, 40);
Box box=Box.createHorizontalBox();
Font font=new Font("楷体_GB2312",Font.BOLD,40);
JLabel l;
l=new JLabel("学生管理系统(v1.1)");
l.setHorizontalTextPosition(JLabel.HEIGHT);
l.setFont(font);
box.add(l,Box.BOTTOM_ALIGNMENT);
flowPanel.add(box,Panel.CENTER_ALIGNMENT);
flowPanel.setBackground(Color.LIGHT_GRAY);
}
public void setPanel2()
{
gridPanel=new Panel();
gridPanel.setSize(600, 360);
gridPanel.setLayout(new GridLayout(1,2));
//Box baseBox1=Box.createHorizontalBox();
setFlowPanel();
setBoxPanel();
gridPanel.add(flowPanel1);
gridPanel.add(boxPanel);
//baseBox1.add(flowPanel1, Box.TOP_ALIGNMENT);
//baseBox1.add(Box.createHorizontalStrut(20));
//baseBox1.add(boxPanel,Box.LEFT_ALIGNMENT);
//gridPanel.add(baseBox1);
}
public void setFlowPanel()
{
flowPanel1=new Panel();
//flowPanel1.setSize(300, 300);
flowPanel1.setLayout(new BorderLayout());
JLabel l=new JLabel(new ImageIcon(".\\icon\\1.jpg"));
flowPanel1.add(l,"Center");
flowPanel1.setBackground(Color.blue);
}
public void setBoxPanel()
{
boxPanel=new Panel();
boxPanel.setSize(300,300);
boxPanel.setLocation(300,100);
boxPanel.setLayout(new BoxLayout(boxPanel,BoxLayout.X_AXIS));
Box baseBox=Box.createVerticalBox();
b1=new JButton(" 输入学生信息 ");
b2=new JButton(" 查询学生信息 ");
b3=new JButton(" 统计平均成绩 ");
b4=new JButton(" 统计总成绩 ");
b5=new JButton(" 关于我们 ");
JLabel ll=new JLabel(" ====功能菜单====");
baseBox.add(Box.createHorizontalStrut(1));
baseBox.add(ll);
baseBox.add(Box.createHorizontalStrut(1));
baseBox.add(b1);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b2);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b3);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b4);
baseBox.add(Box.createVerticalStrut(10));
baseBox.add(b5);
baseBox.add(Box.createHorizontalStrut(1));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
JLabel l=new JLabel(" 科比工作室版权所有,盗版必究。");
//baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(l);
boxPanel.add(baseBox,Panel.TOP_ALIGNMENT);
flowPanel1.setBackground(Color.green);
}
public static void main(String[] args)
{
new ViewFrame();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
exit();
//new ComboBoxDemo();
}
if(e.getSource()==b2)
{
exit();
}
if(e.getSource()==b3)
{
exit();
}
if(e.getSource()==b4)
{
exit();
}
if(e.getSource()==b5)
{
exit();
}
}
}