Java:在Eclipse中调用另一个类时出错
//我设法修复了它,有一个完全不相关的错误,它不是作为错误给出的,我删除了代码,现在它工作了。谢谢你抽出时间 嗨,Java:在Eclipse中调用另一个类时出错,java,eclipse,Java,Eclipse,//我设法修复了它,有一个完全不相关的错误,它不是作为错误给出的,我删除了代码,现在它工作了。谢谢你抽出时间 嗨, 我在Eclipse中创建了一个Java程序,该程序运行良好,尽管我的类中有一个错误,但稍后我将在代码中显示它。我有一个文件夹类,它使用Document类并在单击菜单中的按钮时创建一个新的文件夹类。这曾经工作得很好,但是昨天Eclipse和我的pc发生了一些奇怪的事情,现在它无法工作,即使代码没有一点变化 如果你需要额外的信息或者我觉得问题不对,就说出来。这是我的第一个问题。我还在学
我在Eclipse中创建了一个Java程序,该程序运行良好,尽管我的类中有一个错误,但稍后我将在代码中显示它。我有一个文件夹类,它使用Document类并在单击菜单中的按钮时创建一个新的文件夹类。这曾经工作得很好,但是昨天Eclipse和我的pc发生了一些奇怪的事情,现在它无法工作,即使代码没有一点变化 如果你需要额外的信息或者我觉得问题不对,就说出来。这是我的第一个问题。我还在学习 //编辑 当我将鼠标悬停在Document.java(公共类文档扩展JInternalFrame实现ActionListener)中的错误上时,它会说:
The type Document must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
但当我把它抽象化时,它只会产生更多的错误
Folder.java
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
import java.util.*;
//Main screen
public class Folder extends JFrame implements ActionListener {
public ImageIcon img = new ImageIcon("C:/users/jeroe_000/pictures/flogo.png");
private JFrame JFrame = new JFrame();
private JMenuBar mb = new JMenuBar();
private JMenu men = new JMenu("Window");
private JMenuItem newItem = new JMenuItem("New window");
private JMenuItem closeItem = new JMenuItem("Close all windows");
private JMenuItem exit = new JMenuItem("Close");
public JPanel startscreen = new JPanel();
public boolean opened = false;
public String programName = "Sitebucket Office";
private JDesktopPane bord = new JDesktopPane();
private int n; //number of internal windows
private Folder() {
setContentPane(bord);
setJMenuBar(mb);
mb.add(men);
men.add(newItem); men.add(closeItem); men.addSeparator(); men.add(exit);
Container contentPane = getContentPane();
//connect listener to the menu alternatives
newItem.addActionListener(this);
closeItem.addActionListener(this);
exit.addActionListener(this);
setTitle("Sitebucket Office");
setSize(900, 700);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
startscreen.setVisible(true);
JLabel welcome = new JLabel("Welcome to Sitebucket Office");
contentPane.add(startscreen);
startscreen.add(welcome, BorderLayout.SOUTH);
//Opmaak
bord.setPreferredSize(new Dimension(100, 25));
bord.setBackground(new Color(58, 119, 165, 70 ));
bord.setForeground(new Color(255, 255, 255));
mb.setBackground(new Color(58, 119, 165));
mb.setForeground(new Color(255, 255, 255));
men.setBackground(new Color(58, 119, 165));
men.setForeground(new Color(255, 255, 255));
men.setFont(new Font("Oxygen Light", Font.PLAIN, 20));
newItem.setBackground(new Color(58, 119, 165));
newItem.setForeground(new Color(255, 255, 255));
newItem.setFont(new Font("Oxygen Light", Font.PLAIN, 14));
closeItem.setBackground(new Color(58, 119, 165));
closeItem.setForeground(new Color(255, 255, 255));
closeItem.setFont(new Font("Oxygen Light", Font.PLAIN, 14));
exit.setBackground(new Color(58, 119, 165));
exit.setForeground(new Color(255, 255, 255));
exit.setFont(new Font("Oxygen Light", Font.PLAIN, 14));
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == newItem) {
Document f = new Document("Document " + (n+1));
bord.add(f);
int x = Math.min(30*n, bord.getWidth() - f.getWidth());
int y = Math.min(30*n, bord.getHeight() - f.getHeight());
f.setLocation(x, y);
f.moveToFront();
n++;
}
else if (e.getSource() == closeItem) {
JInternalFrame[] a = bord.getAllFrames();
for (int i=0; i<a.length; i++)
a[i].dispose();
n = 0;
}
else if (e.getSource() == exit){
System.exit(0);
}
}
public static void main (String arg[]) {
new Folder();
}
}
IntPaintWindow.java
import javax.swing.*;
import java.awt.*;
public class IntPaintWindow extends JInternalFrame{
public IntPaintWindow(String title){
super(title, true, true, true, true);
setSize(400, 300);
setVisible(true);
}
}
错误
我知道这是很多信息,但如果你们能帮我修复这个错误,我将非常感激
您好,Jeroen尝试更改文档类的名称“未解决的编译问题”意味着您的源文件和编译的类文件不同步。删除所有已编译的类文件并重新编译所有源文件。可能它认为您指的是java.swing.text.Document,而不是名为Document的类。更改名称不起作用。@iJeroen然后是什么问题?单击该行右侧的符号,然后单击
添加未混合方法
import javax.swing.*;
import java.awt.*;
public class IntPaintWindow extends JInternalFrame{
public IntPaintWindow(String title){
super(title, true, true, true, true);
setSize(400, 300);
setVisible(true);
}
}
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Cannot instantiate the type Document
at Folder.actionPerformed(Folder.java:84)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)