java程序中GUI编程的缺乏main方法的代码如何运行,已经省略了部分代码,main应该加在哪里怎么加

已举报 回答
java程序中GUI编程的缺乏main方法的代码如何运行,已经省略了部分代码,main应该加在哪里怎么加
问在线客服
扫码问在线客服
  • 回答数

    3

  • 浏览数

    690

3个回答 默认排序
  • 默认排序
  • 按时间排序

已采纳
加了两处 // add
你看看,  
------------------------------------------------------------------------------------------------
public class MainFrame extends JFrame implements ActionListener {
// add
public static void main(String[] args){
new MainFrame(MainFrame);
}
InsertPanel ip = null;
SelectPanel sp = null;
SelectscorePanel sp2 = null;
Insert2Panel ip2 = null;
DeletePanel dp = null;
JPanel pframe;
JButton jb1, jb2, jb3;
JMenuItem jm11, jm21, jm22, jm23, jm31, jm32;
CardLayout clayout;
MainFrame(String s) {
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu(系统);
JMenu m2 = new JMenu(基本信息);
JMenu m3 = new JMenu(成绩);
mb.add(m1);
mb.add(m2);
mb.add(m3);
jm11 = new JMenuItem(退出系统);
jm21 = new JMenuItem(输入);
jm22 = new JMenuItem(查询);
jm23 = new JMenuItem(删除);
jm31 = new JMenuItem(输入成绩);
jm32 = new JMenuItem(查询成绩);
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
jb1 = new JButton(i1);
jb2 = new JButton(i2);
jb3 = new JButton(i3);
JToolBar tb = new JToolBar(系统工具);
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb, BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jm23.addActionListener(this);
jm31.addActionListener(this);
jm32.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel(学生信息管理平台, SwingConstants.CENTER);
mainl.setFont(new Font(Serif, Font.BOLD, 30));
mainp.add(mainl);
pframe.add(mainp, main);
clayout.show(pframe, main);
// add
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jm21 | e.getSource() == jb1) {
if (ip == null) {
ip = new InsertPanel();
pframe.add(ip, insert);
}
clayout.show(pframe, insert);
this.setTitle(输入学生信息);
} else if (e.getSource() == jm22 | e.getSource() == jb2) {
if (sp == null) {
sp = new SelectPanel();
pframe.add(sp, select);
}
clayout.show(pframe, select);
this.setTitle(查询学生信息);
} else if (e.getSource() == jm22 | e.getSource() == jb2) {
if (sp == null) {
sp = new SelectPanel();
pframe.add(sp, select);
}
clayout.show(pframe, select);
this.setTitle(查询学生信息);
} else if (e.getSource() == jm23) {
if (dp == null) {
dp = new DeletePanel();
pframe.add(dp, delete);
}
clayout.show(pframe, delete);
this.setTitle(输入学生成绩);
} else if (e.getSource() == jm31) {
if (ip2 == null) {
ip2 = new Insert2Panel();
pframe.add(ip2, insert2);
}
clayout.show(pframe, insert2);
this.setTitle(输入学生成绩);
} else if (e.getSource() == jm32) {
if (sp2 == null) {
sp2 = new SelectscorePanel();
pframe.add(sp2, select2);
}
clayout.show(pframe, select2);
this.setTitle(查询学生成绩);
} else if ((e.getSource() == jm11) | (e.getSource() == jb3))
System.exit(0);
}
}
取消 评论
可以直接第三行后面加,到下一个public 函数结束
取消 评论
你在最后一个花括号之前加main函数即可:
public static void main(String[] args){
}

}//这里是你最后的花括号,也就是MainFrame类的结束括号。
取消 评论
ZOL问答 > java程序中GUI编程的缺乏main方法的代码如何运行,已经省略了部分代码,main应该加在哪里怎么加

举报

感谢您为社区的和谐贡献力量请选择举报类型

举报成功

经过核实后将会做出处理
感谢您为社区和谐做出贡献

扫码参与新品0元试用
晒单、顶楼豪礼等你拿

扫一扫,关注我们
提示

确定要取消此次报名,退出该活动?