java - 显示 java GUI 的问题。它不会显示。我还是新手,也许包类有问题或其他什么
问题描述
所以我正在制作这个用于巴士预订的 GUI,但它似乎没有运行。我还是 Java 编程的新手。
不知道是类包的问题还是其他的问题。
从 netbeans 收到一条错误消息:
线程“main”java.lang.RuntimeException 中的异常:无法编译的源代码 - 内部类 gui2.MyFrame.frm 修饰符“static”中的非法静态声明只允许在 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();
}
}
解决方案
推荐阅读
- hex - 如果支持的最大数据类型为 32 位长,如何将保存为 HEX 格式的 7 字节数字转换为十进制数字?
- multithreading - 同步服务中的奇怪行为
- android - 如何用 Firebase Flutter 替换物品
- html - 当绝对值时,Css divs 被放置在另一个前面
- c# - 中间件使用从客户端发送的参数,并根据这些参数允许或不允许与端点交互
- linux - API CALL 上不允许此令牌的 IP 地址
- javascript - 获取没有 CORS 问题的 GitHub 源 tarball
- ios - 在 Xcode 中打开 Popover 选项以在 iPad 上选择相机或照片库时出错
- html - 捕获对象标签或 IFrame 的屏幕截图
- python - 如何在 Django 中管理多个提交按钮?