4
回答
用java编写了一个界面 代码没有问题错误 可是运行后出现问题提示 求大神……
华为云4核8G,高性能云服务器,免费试用   
package Orders;


import java.awt.BorderLayout;
import java.awt.Component;
import java.net.URL;


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;
import javax.swing.JTextArea;


public class TicketsOrder extends JFrame {


public TicketsOrder() {
init();
}
private void init(){
this.setSize(400,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(createContentPane());

}
private JPanel createContentPane(){
JPanel p = new JPanel(new BorderLayout());
p.add(BorderLayout.NORTH,createTopPane());
p.add(BorderLayout.CENTER,createCenterPane());
p.add(BorderLayout.SOUTH,createSouthPane());
return p;
}
private JPanel createTopPane(){
JPanel p = new JPanel();
// URL urlImage = 
ImageIcon imageIcon = new ImageIcon(this.getClass().getResource("/images/3.jpg"));
JLabel jl = new JLabel(imageIcon,JLabel.CENTER);
p.add(jl);
return p;
}
private JPanel createCenterPane(){
JPanel p = new JPanel();
JFrame jf = new JFrame();
JMenuBar menuBar = new JMenuBar();
jf.setJMenuBar(menuBar);
JMenu orders = new JMenu("车票预订");
JMenu remainTickets = new JMenu("余票查询");
JMenu timeQuery = new JMenu("列车时刻表查询");
JMenu buyTimeQuery = new JMenu("起售时间查询");
JMenu lateQuery = new JMenu("晚点查询");
JMenu ticketsDaiShouDian = new JMenu("客票代售点");
JMenu railwayTripPlan= new JMenu("铁路旅程规划");
menuBar.add(orders);
menuBar.add(remainTickets);
menuBar.add(timeQuery);
menuBar.add(buyTimeQuery);
menuBar.add(lateQuery);
menuBar.add(ticketsDaiShouDian);
menuBar.add(railwayTripPlan);
JMenuItem checichaxun = new JMenuItem("车次查询");
JMenuItem fadaozhanchaxun = new JMenuItem("发到站查询");
JMenuItem ticketsprice = new JMenuItem("票价查询");
JMenuItem zhongzhuanchaxun = new JMenuItem("中转查询");
JMenuItem chezhanjingguochecichaxun = new JMenuItem("车站经过车次查询");
timeQuery.add(checichaxun);
timeQuery.add(fadaozhanchaxun);
timeQuery.add(ticketsprice);
timeQuery.add(zhongzhuanchaxun);
timeQuery.add(chezhanjingguochecichaxun);
p.add(jf);
return p ;
}
private JPanel createSouthPane(){
JPanel p = new JPanel(new BorderLayout());
URL urlImage1 = this.getClass().getResource("/images/5.jpg");
URL urlImage2 = this.getClass().getResource("/images/4.jpg");

ImageIcon imageIcon1 = new ImageIcon(urlImage1);
ImageIcon imageIcon2 = new ImageIcon(urlImage2);
JLabel jl1 = new JLabel(imageIcon1);
JLabel jl2 = new JLabel(imageIcon2);
p.add(BorderLayout.NORTH,jl1);
p.add(BorderLayout.SOUTH,jl2);
p.add(BorderLayout.NORTH,createQueryPane());
return p;
}
private JPanel createQueryPane(){
JPanel p = new JPanel();
JTextArea jta = new JTextArea();
p.add(jta);
return p;
}

}

运行错误提示如下

Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Container.java:431)
at java.awt.Container.addImpl(Container.java:1039)
at java.awt.Container.add(Container.java:365)
at Orders.TicketsOrder.createCenterPane(TicketsOrder.java:71)
at Orders.TicketsOrder.createContentPane(TicketsOrder.java:30)
at Orders.TicketsOrder.init(TicketsOrder.java:24)
at Orders.TicketsOrder.<init>(TicketsOrder.java:19)
at ordersTest.TiketsOrderTest.main(TiketsOrderTest.java:5)



举报
顶部