Итак, я делаю это GUI для резервирования автобуса, но кажется, что t не работает. Я все еще новичок в Java программировании.
Я не знаю, является ли это проблемой пакета класса или других вещей.
получил сообщение об ошибке от netbeans:
Исключение в потоке "main" java .lang.RuntimeException: некомпилируемый исходный код - недопустимое stati c объявление во внутреннем классе gui2.MyFrame.frm Модификатор 'stati c' допускается только в константе объявления переменных в gui2.MyFrame $ frm.main (Student. java: 100)
package gui2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Student implements ActionListener{
private JFrame frame;
private JButton no;
private JButton sub;
private JLabel l1;
private JLabel l2;
private JLabel l3;
private TextField name;
private TextField cate;
private TextField desti;
private JTextArea tout;//ouput interface
public Student(){
frame=new JFrame("TRAIN TICKET");
frame.setSize(800,600);
frame.setLayout(null);
frame.setVisible(true);
no=new JButton("WELCOME TO TRAIN TICKET PADANG BESAR");
no.setBounds(0,0,800,40); //(,,lebar,tinggi)
frame.add(no,BorderLayout.NORTH);
sub = new JButton("Submit");
frame.add(sub);
sub.setBounds(350,500,100,20);
sub.addActionListener(this);
l1 = new JLabel("NAME :");
frame.add(l1);
l1.setBounds(50,45,100,60);
l2 = new JLabel("CATEGORY :");
l2.setBounds(50,60,150,90);;
frame.add(l2);
l3 = new JLabel("DESTINATION :");
frame.add(l3);
l3.setBounds(50,70,150,120);
name = new TextField ();
frame.add(name);
name.setBounds(200,60,200,20);
cate= new TextField ();
frame.add(cate);
cate.setBounds(200,90,200,20);
desti= new TextField ();
frame.add(desti);
desti.setBounds(200,125,200,20);
tout = new JTextArea();
frame.add(tout);
tout.setBounds(450,50,300,400);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == sub)
{
double price = 0.0;
double charge = 0.0;
String data1,data2,data3;
data1 = l1.getText();
data2 = l2.getText();
data3 = l3.getText();
if (data1.equals("Alor Setar")) {
price = 5.0;
}
else if (data2.equals("Sungai Petani")) {
price = 5.0;
}
else if (data2.equals("Anak Bukit")) {
price = 6.0;
}
else if (data2.equals("Tasek Gelugor")) {
price = 11.0;
}
else if (data2.equals("Gurun")) {
price = 9.0;
}
if (data3.equals("Children")) {
charge = 0.20;
}
else if (data3.equals("Adult")) {
charge = 0.0;
}
else if (data3.equals("Elder")) {
charge = 0.15;
}
double total = ( price * 0.06 ) + price + (price * charge);
l1.setText(data1);
l2.setText(data2);
l3.setText(String.valueOf(total));
}
}
public static void main(String args[]) {
Student app=new Student();
}
}