我想通过点击StuManaSystem这个GUI的一个菜单项来启动另一个GUI界面(TextAreaDemo),应该在StuManaSystem这个类的下面的actionPerformed方法(下面有注释)里面添加什么样的代码才行呢? 组合?还是继承? 我先把两个文件放在一个目录下,在把代码放上来,谁帮我解决下问题啊 谢谢了先。
下面这个是第一个文件~!!!!!!!!!!!!!!!!!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class StuManaSystem extends JFrame{
public StuManaSystem()
{
super("学生成绩管理系统");
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
JMenu[] menu ={new JMenu("成绩管理"),
new JMenu("成绩查询"),new JMenu("详细信息"),new JMenu("其他信息")};
JMenuItem[] menuitem={new JMenuItem("成绩输入"),new JMenuItem("成绩输出"),
new JMenuItem("平均成绩"),new JMenuItem("总成绩"),new JMenuItem("单科成绩"),
new JMenuItem("学院信息"),new JMenuItem("专业信息"),new JMenuItem("班级信息"),
new JMenuItem("个人信息"),new JMenuItem("学生名次")};
menuitem[0].addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//这里应该加如什么代码才可以完整的驱动显示下面的第2个文件的界面呢?
}
}
);
for(int i=0;i<menu.length;i++)
bar.add(menu[i]);
for(int i=0;i<2;i++)
menu[0].add(menuitem[i]);
for(int i=2;i<5;i++)
menu[1].add(menuitem[i]);
for(int i=5;i<9;i++)
menu[2].add(menuitem[i]);
menu[3].add(menuitem[9]);
setSize(500,500);
show();
}
public static void main(String[] args)
{
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e){
throw new RuntimeException(e);
}
StuManaSystem app = new StuManaSystem();
app.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}这是第2个文件~!!!!!!!!!!!!!!!!!!!!!!!!!!!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class TextAreaDemo extends JFrame{
private JTextArea t1,t2;
private JButton copy; public TextAreaDemo()
{
super("TextArea演示");
Box b= Box.createHorizontalBox();
String s="哈哈哈哈哈哈\n"+"呵呵呵呵饿而后呵呵\n"; t1=new JTextArea(s,10,10);
b.add(new JScrollPane(t1) );
copy=new JButton("复制>>");
copy.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
t2.setText(t1.getSelectedText() );
}
}
);
b.add(copy); t2=new JTextArea(10,10);
t2.setEditable(false);
b.add(new JScrollPane(t2) );
Container c=getContentPane();
c.add(b);
setSize(425,200);
show();
} public static void main(String args[])
{
TextAreaDemo app=new TextAreaDemo(); app.addWindowListener(
new WindowAdapter(){
public void winodwClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
下面这个是第一个文件~!!!!!!!!!!!!!!!!!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;public class StuManaSystem extends JFrame{
public StuManaSystem()
{
super("学生成绩管理系统");
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
JMenu[] menu ={new JMenu("成绩管理"),
new JMenu("成绩查询"),new JMenu("详细信息"),new JMenu("其他信息")};
JMenuItem[] menuitem={new JMenuItem("成绩输入"),new JMenuItem("成绩输出"),
new JMenuItem("平均成绩"),new JMenuItem("总成绩"),new JMenuItem("单科成绩"),
new JMenuItem("学院信息"),new JMenuItem("专业信息"),new JMenuItem("班级信息"),
new JMenuItem("个人信息"),new JMenuItem("学生名次")};
menuitem[0].addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//这里应该加如什么代码才可以完整的驱动显示下面的第2个文件的界面呢?
}
}
);
for(int i=0;i<menu.length;i++)
bar.add(menu[i]);
for(int i=0;i<2;i++)
menu[0].add(menuitem[i]);
for(int i=2;i<5;i++)
menu[1].add(menuitem[i]);
for(int i=5;i<9;i++)
menu[2].add(menuitem[i]);
menu[3].add(menuitem[9]);
setSize(500,500);
show();
}
public static void main(String[] args)
{
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch(Exception e){
throw new RuntimeException(e);
}
StuManaSystem app = new StuManaSystem();
app.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}这是第2个文件~!!!!!!!!!!!!!!!!!!!!!!!!!!!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;public class TextAreaDemo extends JFrame{
private JTextArea t1,t2;
private JButton copy; public TextAreaDemo()
{
super("TextArea演示");
Box b= Box.createHorizontalBox();
String s="哈哈哈哈哈哈\n"+"呵呵呵呵饿而后呵呵\n"; t1=new JTextArea(s,10,10);
b.add(new JScrollPane(t1) );
copy=new JButton("复制>>");
copy.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
t2.setText(t1.getSelectedText() );
}
}
);
b.add(copy); t2=new JTextArea(10,10);
t2.setEditable(false);
b.add(new JScrollPane(t2) );
Container c=getContentPane();
c.add(b);
setSize(425,200);
show();
} public static void main(String args[])
{
TextAreaDemo app=new TextAreaDemo(); app.addWindowListener(
new WindowAdapter(){
public void winodwClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
class Jcheng extends TextAreaDemo
{ Jcheng j=new Jcheng();
}但是这样会有错的,, 但是用继承的方法应该行吧? 具体应该怎么操作呢?