我创建了一个java程序,但我无法在netbeans中运行它。当我尝试从另一个文件导入名为invice的类时。它抛出错误说
error: cannot find symbol
invice invc=new invice();
该计划如下。我在一个名为Invicedemo
的类中编写了main函数package invicedemo;
public class Invicedemo {
public static void main(String[] args) {
invice invc=new invice();
invc.setSize(300,250);
invc.setTitle("party memo");
invc.setVisible(true);
}
}
我尝试导入的类与文件名invice.java
在同一个包中import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class invice extends JFrame implements ActionListener, KeyListener, FocusListener {
JTextField tf, tf1, tf2, tf3;
JButton bt, bt1;
JLabel lb, lb1, lb2, lb3;
Container cn;
public invice() {
cn = getContentPane();
cn.setLayout(null);
lb = new JLabel("Bill No.:");
lb.setBounds(10, 10, 70, 25);
cn.add(lb);
tf = new JTextField();
tf.setBounds(100, 10, 150, 25);
cn.add(tf);
lb1 = new JLabel("Party Name:");
lb1.setBounds(10, 40, 70, 25);
cn.add(lb1);
tf1 = new JTextField();
tf1.setBounds(100, 40, 150, 25);
cn.add(tf1);
lb2 = new JLabel("Date:");
lb2.setBounds(10, 70, 70, 25);
cn.add(lb2);
tf2 = new JTextField();
tf2.setBounds(100, 70, 150, 25);
cn.add(tf2);
lb3 = new JLabel("Gr No.:");
lb3.setBounds(10, 100, 70, 25);
cn.add(lb3);
tf3 = new JTextField();
tf3.setBounds(100, 100, 150, 25);
cn.add(tf3);
bt = new JButton("Store:");
bt.setBounds(30, 160, 70, 25);
cn.add(bt);
bt1 = new JButton("Cancel:");
bt1.setBounds(150, 160, 80, 25);
cn.add(bt1);
tf.addKeyListener(this);
tf1.addKeyListener(this);
tf2.addKeyListener(this);
tf.addFocusListener(this);
tf1.addFocusListener(this);
tf2.addFocusListener(this);
bt.addKeyListener(this);
bt.addFocusListener(this);
tf3.addKeyListener(this);
tf3.addFocusListener(this);
bt1.addKeyListener(this);
bt1.addFocusListener(this);
bt.addActionListener(this);
bt1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == bt) {
String party_name = tf.getText();
String date = tf1.getText();
String gr_no = tf2.getText();
String Sno = tf3.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "asiya");
Statement st = con.createStatement();
st.executeUpdate("Insert into invis values('" + Sno + "','" + party_name + "', '" + date + "', '" + gr_no + "')");
JOptionPane.showMessageDialog(cn, "your data is successfully store", "storage", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(cn, e, "storage", JOptionPane.INFORMATION_MESSAGE);
}
}
if (ae.getSource() == bt1) {
tf.setText("");
tf1.setText("");
tf2.setText("");
tf3.setText("");
}
}
public void keyPressed(KeyEvent ke) {
if (ke.getSource() == tf && ke.getKeyCode() == KeyEvent.VK_ENTER) {
tf1.requestFocus();
}
if (ke.getSource() == tf1 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
tf2.requestFocus();
}
if (ke.getSource() == tf2 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
tf3.requestFocus();
}
if (ke.getSource() == tf3 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
bt.requestFocus();
}
if (ke.getSource() == bt && ke.getKeyCode() == KeyEvent.VK_ENTER) {
bt1.requestFocus();
tf.setText("");
tf1.setText("");
tf2.setText("");
}
}
public void keyTyped(KeyEvent ke) {
}
public void keyReleased(KeyEvent ke) {
}
public void focusGained(FocusEvent fe) {
}
public void focusLost(FocusEvent fe) {
}
}
任何人都能说出我在做什么错误。
答案 0 :(得分:1)
你忘记了第二堂课中的package
陈述:
package invicedemo;
class invice ... { ... }