我正在尝试调用位于同一目录中并已编译的另一个类。当我调用其他类时,我不断收到未找到的错误符号。任何人都可以看看我的代码,看看我做错了什么。
这是代码:
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class NameGameFrame extends JFrame
{
public static String name;
static JTextField textfield = new JTextField(20);
static JTextArea textarea = new JTextArea(30,30);
public static void main( String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Name Game");
frame.setLocation(500,400);
frame.setSize(800,800);
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel label = new JLabel("Enter the Name or Partial Name to search:");
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(2,2,2,2);
panel.add(label,c);
c.gridx = 0;
c.gridy = 1;
panel.add(textarea,c);
JButton button = new JButton("Search");
c.gridx = 1;
c.gridy = 1;
panel.add(button,c);
c.gridx = 1;
c.gridy = 0;
panel.add(textfield,c);
frame.getContentPane().add(panel, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
name = textfield.getText();
java.io.File file = new java.io.File("namesdata.txt");
try
{
Scanner input = new Scanner(file);
num = input.nextLine();
while (input.hasNext())
{
NameRecord(name);
}
}
catch(FileNotFoundException e)
{
System.err.format("File does not exist\n");
}
textarea.setText(fields[0]);
}
});
}
}
NameRecord 是我正在调用的另一个类的名称。我还需要在我调用的第二个文件类的标题中添加一些内容吗?