Java JFrame问题
packagefj.main;importjava.awt.BorderLayout;importjavax.swing.ImageIcon;importjavax.sw...
package fj.main;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class AirLineSystem extends JFrame {
JPanel imagePanel = null;
JLabel image = null;
JMenuBar menubar = null;
JMenu menu = null;
JMenuItem passIt = null;
JMenuItem airLineIt = null;
JMenuItem ticketIt = null;
public AirLineSystem() {
image = new JLabel(new ImageIcon("images/plane.jpg"));
imagePanel = new JPanel();
menubar = new JMenuBar();
menu = new JMenu();
passIt = new JMenuItem("乘客查询");
airLineIt = new JMenuItem("乘客管理");
ticketIt = new JMenuItem("票务查询");
menu.add(airLineIt);
menu.add(ticketIt);
menu.add(passIt);
menubar.add(menu);
this.setJMenuBar(menubar);
imagePanel.add(image);
this.add(imagePanel,BorderLayout.CENTER);
}
public void show() {
this.setLocation(300,200);
this.setSize(400,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new AirLineSystem().show();
}
}
很简单的一个生成窗口的程序。 为什么出错了?
下面是出错信息:
Exception in thread "main" java.lang.StackOverflowError
at java.awt.Component.reshape(Unknown Source)
at java.awt.Window.reshape(Unknown Source)
at java.awt.Component.setBounds(Unknown Source)
at java.awt.Window.setBounds(Unknown Source)
at java.awt.Component.move(Unknown Source)
at java.awt.Component.setLocation(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:40)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:43)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:43) 展开
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class AirLineSystem extends JFrame {
JPanel imagePanel = null;
JLabel image = null;
JMenuBar menubar = null;
JMenu menu = null;
JMenuItem passIt = null;
JMenuItem airLineIt = null;
JMenuItem ticketIt = null;
public AirLineSystem() {
image = new JLabel(new ImageIcon("images/plane.jpg"));
imagePanel = new JPanel();
menubar = new JMenuBar();
menu = new JMenu();
passIt = new JMenuItem("乘客查询");
airLineIt = new JMenuItem("乘客管理");
ticketIt = new JMenuItem("票务查询");
menu.add(airLineIt);
menu.add(ticketIt);
menu.add(passIt);
menubar.add(menu);
this.setJMenuBar(menubar);
imagePanel.add(image);
this.add(imagePanel,BorderLayout.CENTER);
}
public void show() {
this.setLocation(300,200);
this.setSize(400,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new AirLineSystem().show();
}
}
很简单的一个生成窗口的程序。 为什么出错了?
下面是出错信息:
Exception in thread "main" java.lang.StackOverflowError
at java.awt.Component.reshape(Unknown Source)
at java.awt.Window.reshape(Unknown Source)
at java.awt.Component.setBounds(Unknown Source)
at java.awt.Window.setBounds(Unknown Source)
at java.awt.Component.move(Unknown Source)
at java.awt.Component.setLocation(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:40)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:43)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at fj.main.AirLineSystem.show(AirLineSystem.java:43) 展开
1个回答
展开全部
你不小心重写了系统方法show();
将你的自定义方法名与系统方法错开就行了
public void shows() {//比如在这里多加一个s,反正不能是show()就对了
this.setLocation(300,200);
this.setSize(400,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
下面的语句也要跟着改了
new AirLineSystem().shows();
你的
menu = new JMenu();
最好给它加点东西,不然显示出来没啥效果
menu = new JMenu("菜单");
将你的自定义方法名与系统方法错开就行了
public void shows() {//比如在这里多加一个s,反正不能是show()就对了
this.setLocation(300,200);
this.setSize(400,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
下面的语句也要跟着改了
new AirLineSystem().shows();
你的
menu = new JMenu();
最好给它加点东西,不然显示出来没啥效果
menu = new JMenu("菜单");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询