关于JAVA 的问题!高手请进!急!!!
发布网友
发布时间:2024-04-23 04:17
我来回答
共4个回答
热心网友
时间:2024-06-18 12:30
这里:
jlPrice.add(jlPrice);
怎么能自己添加自己呢???!!!!!
还有,你的JButtom在哪里定义的???
给你凑乎的改了一下:
自己看吧:
import java.awt.*;
import javax.swing.*;
//import java.awt.event.*;
public class Ticketing extends JFrame {
// declare class varibles
// jp,jl,jb,jtf indicate the component typs
// JPanle,JLabel,JButton,JTextField respectively;
private JPanel jpTitle, jpSeat, jpInfo, jpRpack, jpSum, jpTop, jpBottom;
private JButton jb1, jb2, jb3, jb4, jb5, jb6, jb7, jb8, jb9, jb10, jb11,
jb12, jb13, jb14;
private JButton jb15, jbCon, jbReset;
private JLabel jlTitle, jlReserve, jlSeat, jlPrice, jlRPack, jlQuantity,
jlNumOfSeat;
private JLabel jlCost1, jlTicket, jlCost2, jlRF, jlPayment;
private JTextField jtf1;
public static void main(String[] args) {
Ticketing t = new Ticketing();
t.setVisible(true);
}// end of main
/* constructor */
public Ticketing() {
setSize(400,600);//600, 800);
setTitle("OTS");
getContentPane().setLayout(new BorderLayout(4, 1));
/** ***jpTop to contain jpTitle,jpREserve,jpSeat,jpInfo**** */
jpTop = new JPanel();
jpTop.setLayout(new BorderLayout());
/** **Title*** */
jpTitle = new JPanel();
jpTitle.setLayout(new GridLayout(2, 1));
// Font bigFont=new Font("TimesRoman", Font.BOLD,24);
// jpTitle.setBackground(Color.yellow);
jlTitle = new JLabel("Roxy Theatres - Online Ticketing System");
// jlTitle.setFont(bigFont);
jlReserve = new JLabel("Reserve seats by clicking on them!");
jpTitle.add(jlTitle);
jpTitle.add(jlReserve);
jpTop.add(jpTitle, BorderLayout.NORTH);
/** **Seat*** */
jpSeat = new JPanel();
jpSeat.setLayout(new GridLayout(5, 3, 10, 10));
jb1 = new JButton();
jb2 = new JButton();
jb3 = new JButton();
jb4 = new JButton();
jb5 = new JButton();
jb6 = new JButton();
jb7 = new JButton();
jb8 = new JButton();
jb9 = new JButton();
jb10 = new JButton();
jb11 = new JButton();
jb12 = new JButton();
jb13 = new JButton();
jb14 = new JButton();
jb15 = new JButton();
jpSeat.add(jb1);
jpSeat.add(jb2);
jpSeat.add(jb3);
jpSeat.add(jb4);
jpSeat.add(jb5);
jpSeat.add(jb6);
jpSeat.add(jb7);
jpSeat.add(jb8);
jpSeat.add(jb9);
jpSeat.add(jb10);
jpSeat.add(jb11);
jpSeat.add(jb12);
jpSeat.add(jb13);
jpSeat.add(jb14);
jpSeat.add(jb15);
jpTop.add(jpSeat, BorderLayout.CENTER);
/** **Information*** */
jpInfo = new JPanel();
jlSeat = new JLabel("Seats Available:BLUE Reserved:RED");
jlPrice = new JLabel(
"Price per ticket: $8.50($8 promo price for 3 or more)");
jpInfo.add(jlSeat);
jpBottom = new JPanel();
jpBottom.add(jlPrice);
jpTop.add(jpInfo, BorderLayout.SOUTH);
getContentPane().add(jpTop,BorderLayout.CENTER);
getContentPane().add(jpBottom,BorderLayout.SOUTH);
}
}
热心网友
时间:2024-06-18 12:26
你这段代码做什么偶看不出来
但是偶知道你错在什么地方啊
要把红旗送给偶的哦
1 倒数第2行
getContentPane().add(jpBottom);
这是一个空指针异常拉,你没有创建jpBottom这个对象拉
2 jlPrice.add(jlPrice);
这个...,你怎么能用自己添加自己呢,晕
JPanel这个类有好多add()方法继承自Container类,自己慢慢看哈,但是就是不可以自己添自己 >_<!
热心网友
时间:2024-06-18 12:27
来个高手帮他啊 我是没希望了~
热心网友
时间:2024-06-18 12:25
看清楚了你的jlPrice是声明的什么实例啊,怎么可以有jlPrice.add(jlPrice); 呢?
还有你的jpBottom也没有创建,声明对象时后面都少了逗点符!