bookpirate/
-Window.java
-Navigator.java
-NavEventHandler.java
所有文件都有
“包裹盗版”
以下是我如何导入它们的:
导航器类:
package bookpirate;
import javax.swing.*;
import java.awt.*;
import bookpirate.NavEventHandler;
public class Navigator
{
private JPanel panel;
public JTextField page;
public JButton pageBack;
public JButton addBefore;
public JButton addAfter;
public JButton pageForward;
public JButton removePage;
public JButton undo;
public JTextField getPage() { return page; }
public JButton getPageBack() { return pageBack; }
public JButton getAddBefore() { return addBefore; }
public JButton getAddAfter() { return addAfter; }
public JButton getPageForward() { return pageForward; }
public JButton getRemovePage() { return removePage; }
public JButton getUndo() { return undo; }
public int nOfPages;
public int getNOfPages() { return nOfPages; }
public static void main(String[] args)
{
new Navigator();
}
public Navigator()
{
setListeners();
System.out.println("Created NavEventHandler");
}
private void setListeners()
{
NavEventHandler handler = new NavEventHandler(this);
page.addActionListener(handler);
pageBack.addActionListener(handler);
addBefore.addActionListener(handler);
addAfter.addActionListener(handler);
pageForward.addActionListener(handler);
removePage.addActionListener(handler);
undo.addActionListener(handler);
}
}
NavEventHandler类:
package bookpirate;
import java.awt.event.*;
import javax.swing.*;
import bookpirate.Navigator;
public class NavEventHandler implements ActionListener
{
Navigator navigator;
public NavEventHandler(Navigator nav)
{
navigator = nav;
System.out.println("Created NavEventHandler");
}
public void actionPerformed(ActionEvent event)
{
String string = "actionPerformed";
//if(event.getSource() instanceof Navigator)
//{
if(event.getSource() == navigator.getPageBack())
{ string = "pageBack";}
/*else if(event.getSource() == Navigator.getAddBefore())
{ string = "addBefore";}
else if(event.getSource() == Navigator.getAddAfter())
{ string = "addAfter";}
else if(event.getSource() == Navigator.getPageForward())
{ string = "pageForward";}
else if(event.getSource() == Navigator.getRemovePage())
{ string = "removePage";}
else if(event.getSource() == Navigator.getUndo())
{ string = "undo";}
else if(event.getSource() == Navigator.getPage())
{ string = "page " + event.getActionCommand();}*/
string += " gotSource";
//}
System.out.println(string);
}
public static void main(String[] args)
{
}
}
C:\Users\...\bookpirate>javac NavEventHandler.java
NavEventHandler.java:5: error: cannot find symbol
import bookpirate.Navigator;
^
symbol: class Navigator
location: package bookpirate
NavEventHandler.java:9: error: cannot find symbol
Navigator navigator;
^
尽管我可以编译它们
一起没有错误
C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>javac NavEventHandler.java Navigator.java Window.java
C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>
但我不能把它们一起或分开
C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>java Window Navigator NavEventHandler
Error: Could not find or load main class Window
C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>
Main-Class: Window
我不能在文件中添加.mf
我尽量简洁