Main method not found in class p16, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
//button events
//on pressing a button color changes
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code = p16 width= 140 height=140>
</applet>
*/
public class p16 extends Applet implements ActionListener {
String msg = "";
Button first, second;
public void init() {
first = new Button("yes");
second = new Button("no");
add(first);
add(second);
first.addActionListener(this);
second.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String str = ae.getActionCommand();
if (str.equals("yes")) {
first.setBackground(Color.red);
second.setBackground(Color.white);
msg = "pressed yes";
} else {
second.setBackground(Color.blue);
first.setBackground(Color.white);
msg = "pressed no";
}
repaint();
}
public void paint(Graphics g) {
g.drawString(msg, 13, 12);
}
}
在Netbeans IDE上:您可以在application文件夹中右键单击类并选择run file,但如果您在工具栏中按run按钮,则会出现相同的错误
在Eclipce上:它可以从两个方向运行
ps:“in”、“stdout”和“stdin”是三个外部库,并已成功导入。第一个错误显示中的行61是这行“in in=new in(args[0]);” readAllints()中定义的部分如下:
我是一个半初学者在编码和遇到这个问题。 我只是不知道该在哪里修好它。
我试着编译它,它说没有错误。但当我运行程序时,它说:
为什么我的代码(编译很好)给我以下错误? 在ImageTool类中找不到Main方法,请将Main方法定义为:public static void Main(String[]args)
在执行下面的程序时,我得到错误消息为“错误:在类parent_package.parent中找不到Main方法,请将Main方法定义为:public static void Main(String[]args)”..................有谁知道如何解决这个问题吗?