public class CheckInPanel extends JPanel {……} …… 在其他的类中CheckInPanel c=new CheckInPanel();为什么都会报错can't find symbol;symbol:constructor CheckInPanel(),location:class client.CheckInPanel at line 17如果想在其他类中调用CheckInPanel的对象应该怎么写代码
调试欢乐多
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import com.jbaptech.accp.netbar.server.entity.*;
import com.jbaptech.accp.netbar.server.dao.ComputerDAO;
import com.jbaptech.accp.netbar.server.action.BusinessAction;
public class CheckInPanel extends JPanel {
JLabel computerIdDescLabel = new JLabel();
JLabel cardIdDescLabel = new JLabel();
JTextField cardIdTextField = new JTextField();
JLabel pwdDescLabel = new JLabel();
JLabel dispalyNowTimeDescLabel = new JLabel();
JTextField dispalyNowTimeTextField = new JTextField();
JButton confirmButton = new JButton();
JButton resetButton = new JButton();
JPasswordField passwordFiled = new JPasswordField();
JComboBox computerIdCombox = new JComboBox();
java.util.Date nowTime;
public CheckInPanel(NetBarFeeMangementFrame mFrame) {
try {
mainFrame = mFrame;
jbInit();
}catch(Exception ex) {
ex.printStackTrace();
}
} void jbInit() throws Exception {
this.setLayout(null); computerIdDescLabel.setFont(new java.awt.Font("Serif", 0, 13));
computerIdDescLabel.setHorizontalAlignment(SwingConstants.CENTER);
computerIdDescLabel.setText("机器号码:");
computerIdDescLabel.setBounds(new Rectangle(95, 30, 70, 25)); computerIdCombox.setBounds(new Rectangle(175, 30, 110, 25)); cardIdDescLabel.setFont(new java.awt.Font("Serif", 0, 13));
cardIdDescLabel.setHorizontalAlignment(SwingConstants.CENTER);
cardIdDescLabel.setText("卡 号:");
cardIdDescLabel.setBounds(new Rectangle(95, 75, 70, 25)); cardIdTextField.setText("");
cardIdTextField.setBounds(new Rectangle(175, 75, 110, 25)); pwdDescLabel.setFont(new java.awt.Font("Serif", 0, 13));
pwdDescLabel.setHorizontalAlignment(SwingConstants.CENTER);
pwdDescLabel.setText("密 码:");
pwdDescLabel.setBounds(new Rectangle(95, 120, 70, 25)); passwordFiled.setText("");
passwordFiled.setBounds(new Rectangle(175, 120, 110, 25)); dispalyNowTimeDescLabel.setFont(new java.awt.Font("Serif", 0, 13));
dispalyNowTimeDescLabel.setHorizontalAlignment(SwingConstants.CENTER);
dispalyNowTimeDescLabel.setText("开始时间:");
dispalyNowTimeDescLabel.setBounds(new Rectangle(95, 165, 70, 25)); nowTime = new java.util.Date();//nowTime:Thu Jul 31 09:07:01 CST 2008
SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String dispalyNowTime = HMFromat.format(nowTime);
dispalyNowTimeTextField.setText(dispalyNowTime);
dispalyNowTimeTextField.setBounds(new Rectangle(175, 165, 110, 25));
dispalyNowTimeTextField.setEnabled(false); confirmButton.setBounds(new Rectangle(115, 215, 65, 25));
confirmButton.setText("确认");
confirmButton.addActionListener(new UseInPanel_confirmButton_actionAdapter(this)); resetButton.setBounds(new Rectangle(200, 215, 65, 25));
resetButton.setText("重置");
resetButton.addActionListener(new UseInPanel_resetButton_actionAdapter(this)); this.add(cardIdTextField, null);
this.add(cardIdDescLabel, null);
this.add(pwdDescLabel, null);
this.add(dispalyNowTimeDescLabel, null);
this.add(dispalyNowTimeTextField, null);
this.add(passwordFiled, null);
this.add(computerIdDescLabel, null);
this.add(confirmButton, null);
this.add(resetButton, null);
this.add(computerIdCombox, null); computerIdCombox.addItem("");
ComputerDAO computerDAO=new ComputerDAO();//把向BusinessAction查询改为直接向ComputerDAO查询
ArrayList list =computerDAO.getNoUsedComputerList();
for(int i=0;i<list.size();i++){
Computer computer = (Computer) list.get(i);//****
computerIdCombox.addItem(computer.getId());
}
} void resetButton_actionPerformed(ActionEvent e) {
computerIdCombox.setSelectedIndex(0);
cardIdTextField.setText("");
passwordFiled.setText("");
} void confirmButton_actionPerformed(ActionEvent e) {
String passwordtemp = "";
int Login=1;
String cardId = cardIdTextField.getText().trim();
passwordtemp=passwordFiled.getText().toString();
String computerId = computerIdCombox.getSelectedItem().toString();
if(computerId.trim().length()==0){
JOptionPane.showMessageDialog(this,"请选择机器号!","警告", JOptionPane.WARNING_MESSAGE ,null );
Login=0;}
if(cardId.length()==0){
JOptionPane.showMessageDialog(this,"请输入卡号!","警告", JOptionPane.WARNING_MESSAGE ,null );
Login=0;}
if(passwordtemp.length()==0){
JOptionPane.showMessageDialog(this,"请输入密码!","警告", JOptionPane.WARNING_MESSAGE ,null );
Login=0;}
String dispalyNowTime = dispalyNowTimeTextField.getText();//不加+":00",系统自动加入
if(Login==1)
{
Card card = new Card();
card.setId(cardId);//cardId = cardIdTextField.getText().trim();
card.setPassword(passwordtemp); Record record = new Record();
record.setCardId(cardId);
record.setComputerId(computerId);
record.setBeginTime(dispalyNowTime); Computer computer = new Computer();
computer.setId(computerId); if(BusinessAction.cardIsValid(card)){
if(BusinessAction.cardHaveBalance(card)){
BusinessAction.doStartUseComputerBusiness(record,computer);
}else{
JOptionPane.showMessageDialog(this,"卡余额不足,请充值!","警告", JOptionPane.WARNING_MESSAGE ,null );
}
}else{
JOptionPane.showMessageDialog(this,"卡号或者密码不对!","警告", JOptionPane.WARNING_MESSAGE ,null );
}
}
WelcomePanel welcomePanel2 = new WelcomePanel();
mainFrame.remove(mainFrame.getContentPane());
mainFrame.getContentPane().add(welcomePanel2);
mainFrame.setContentPane(welcomePanel2);
mainFrame.show(); }
private NetBarFeeMangementFrame mainFrame;
}class UseInPanel_resetButton_actionAdapter implements java.awt.event.ActionListener {
CheckInPanel adaptee; UseInPanel_resetButton_actionAdapter(CheckInPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.resetButton_actionPerformed(e);
}
}class UseInPanel_confirmButton_actionAdapter implements java.awt.event.ActionListener {
CheckInPanel adaptee; UseInPanel_confirmButton_actionAdapter(CheckInPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.confirmButton_actionPerformed(e);
}
}
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import com.jbaptech.accp.netbar.client.CheckInPanel;
public class CardDAO {
public CardDAO() {
}
public boolean cardIsValid(Card card) {
boolean cardIsValid = false;
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet res = null;
CheckInPanel c=new CheckInPanel();
try {
dbConnection = ConnectionManager.getConnction();
// 查询数据SQL语句
String strSql = "select * from card where id='" + card.getId()//cardId =CheckInPanel. cardIdTextField.getText().trim();
+ "' and password ='" + card.getPassword() + "'";
if (dbConnection != null) {
System.out.println(dbConnection != null);
} //查询操作
pStatement = dbConnection.prepareStatement(strSql);
res = pStatement.executeQuery();
if (res.next()) {
cardIsValid = true;
}
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
return cardIsValid;
} public boolean cardIsHaveBalance( Card card) {
boolean haveBalance = false;
Connection dbConnection = null;
PreparedStatement pStatement = null;
ResultSet res = null;
try {
dbConnection = ConnectionManager.getConnction();
// 查询数据SQL语句
String strSql = "select * from card where id='" + card.getId()
+ "' and password ='" + card.getPassword() + "'";
if (dbConnection != null) {
System.out.println(dbConnection != null);
}
//查询操作
pStatement = dbConnection.prepareStatement(strSql);
res = pStatement.executeQuery();
if (res.next()) {
int balance = res.getInt("balance");
if (balance >= 2) {
haveBalance = true;
}
}
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} finally {
ConnectionManager.closeStatement(pStatement);
ConnectionManager.closeConnection(dbConnection);
}
return haveBalance;
}}
只能调用这个带参数的
public CheckInPanel(NetBarFeeMangementFrame mFrame)
public CheckInPanel(NetBarFeeMangementFrame mFrame) ,
因此编译器不再提供默认的不带参数的构造函数,因此在其他的类在写如下代码:
CheckInPanel c=new CheckInPanel();
当然出错。