-4
메모장 프로젝트를 간단히 작성하기 위해 Java 코드가 있으며 실행에 문제가 있습니다. 그것은 코드가 경고를 생성하는 것 같습니다. Java에서 NetBeans IDE 8.01을 사용하고 있습니다. 프로그램을 실행하려고하면 상자에 다음 내용이 표시됩니다. firstprojectnote.FirstProjectNote wasn´t found in FirstProjectNote project. select main class <no main class found>
Main에 대한 카테고리가 없다고 생각합니까? 도와 주셔서 감사합니다.주 파일이 누락되었습니다.
package firstprojectnote;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;
public class FirstProjectNote extends JFrame implements ActionListener {
public class notepad {
public void main(String args[]) {
app.setVisible(true);
}
}
private TextArea textArea = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
private MenuBar menuBar = new MenuBar();
private Menu file = new Menu();
private MenuItem openFile = new MenuItem();
private MenuItem saveFile = new MenuItem();
private MenuItem close = new MenuItem();
public FirstProjectNote() {
this.setSize(500, 300);
this.setTitle("Java Notepad Tutorial");
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.textArea.setFont(new Font("Century Gothic", Font.BOLD, 12));
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(textArea);
this.setMenuBar(this.menuBar);
this.menuBar.add(this.file);
this.file.setLabel("File");
this.openFile.setLabel("Open");
this.openFile.addActionListener(this);
this.openFile.setShortcut(new MenuShortcut(KeyEvent.VK_O, false));
this.file.add(this.openFile);
this.saveFile.setLabel("Save");
this.saveFile.addActionListener(this);
this.saveFile.setShortcut(new MenuShortcut(KeyEvent.VK_S, false));
this.file.add(this.saveFile);
this.close.setLabel("Close");
this.close.setShortcut(new MenuShortcut(KeyEvent.VK_F4, false));
this.close.addActionListener(this);
this.file.add(this.close);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == this.close)
this.dispose();
else if (e.getSource() == this.openFile) {
JFileChooser open = new JFileChooser();
int option = open.showOpenDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
this.textArea.setText("");
try {
Scanner scan = new Scanner(new
FileReader(open.getSelectedFile().getPath()));
while (scan.hasNext())
this.textArea.append(scan.nextLine() + "\n");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
} else if (e.getSource() == this.saveFile) {
JFileChooser save = new JFileChooser();
int option = save.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
try {
BufferedWriter out = new BufferedWriter(new
FileWriter(save.getSelectedFile().getPath()));
out.write(this.textArea.getText());
out.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
}
}
덕분에,이 오류 만들 것 "불법 정적 선언 statis는 상수 선언에서 사용할 수 있습니다." 그래서 나는 그것을 벗었다 – NAME12345
내가 당신을 위해 그것을 보라. 코드에서 정적 선언을 변경 한 유일한 것이 있습니까? – MarkHorwell
죄송합니다. 크리스마스가 내 방식대로있어. 내부 클래스를 정적으로 만들려고 시도 했습니까? 다음'public static class notepad { } public static void main (String args []) { } app.setVisible (true); 다음을 참조하십시오. } } '. 여기서 문제는 none 정적 중첩 클래스 내에서 정적 메서드가 호스팅된다는 것입니다. 나가서 문제가 있는지 알려주세요. – MarkHorwell