?? customerlogin.java
字號:
package clientpack;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.io.PrintStream;
import java.util.Scanner;
import java.awt.Toolkit;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JRadioButton;
import javax.swing.ListSelectionModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.awt.*;
public class CustomerLogin extends JFrame {
private static final long serialVersionUID = 1L;
private String id;
private MyMessage mm;
private Message mes;
private boolean iflog;
private int RowNum;
private int RowNumsoftsell;
private int RowNumsoft;
private int RowNumrestaurant;
private int RowNumfood;
private int RowNummyfood;
private DefaultTableModel model2;
private ButtonGroup SoftGroup = null; // @jve:decl-index=0:
private ButtonGroup RestraurantGroup = null; // @jve:decl-index=0:
private JPanel jContentPane = null;
private JButton personalbank = null;
private JButton buy = null;
private JButton gotorestaurant = null;
private JButton myrecord = null;
private JPanel bankPanel = null;
private JPanel softwarePanel = null;
private JPanel restaurantPanel = null;
private JButton checkaccount = null;
private JButton deposit = null;
private JButton withdraw = null;
private JButton transfer = null;
private JButton loan = null;
private JPanel bankenterPanel = null;
private JPasswordField jPasswordField = null;
private JLabel jLabel = null;
private JButton enter = null;
private JLabel jLabel1 = null;
private JButton newaccount = null;
private JPanel regaccountPanel = null;
private JPasswordField regpassword = null;
private JPasswordField regpasswordconfirm = null;
private JTextField regaccount = null;
private JTextField regcash = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JButton regok = null;
private JButton regback = null;
private JTextField bankpanel_jTextField = null;
private JTextField bankpanel_jTextField2 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private JLabel jLabel8 = null;
private JButton bankpanel_deposit = null;
private JButton bankpanel_withdraw = null;
private JButton bankpanel_transfer = null;
private JButton bankpanel_loan = null;
private JLabel note_jLabel = null;
private JButton checkloan_jButton = null;
private JButton checksoft_jButton = null;
private JButton payback_jButton = null;
private JButton feedback_jButton = null;
private JTextField feedback_jTextField = null;
private JPanel myrecord_jPanel = null;
private JScrollPane myrecord_jScrollPane = null;
private JTable myrecord_jTable = null;
private JScrollPane softsellview_jScrollPane = null;
private JTable softsellview_jTable = null;
private JScrollPane softview_jScrollPane = null;
private JTable softview_jTable = null;
private JButton buy_jButton = null;
private JRadioButton transfer_jRadioButton = null;
private JRadioButton cash_jRadioButton = null;
private JScrollPane restaurantview_jScrollPane = null;
private JTable restaurantview_jTable = null;
private JScrollPane foodview_jScrollPane = null;
private JTable foodview_jTable = null;
private JRadioButton foodpaytransfer_jRadioButton = null;
private JRadioButton foodpaycash_jRadioButton = null;
private JButton foodorder_jButton = null;
private JScrollPane myfood_jScrollPane = null;
private JTable myfood_jTable = null;
/**
* This is the default constructor
*/
public CustomerLogin(Scanner pin, PrintStream pout,String sid) {
super();
initialize();
id = sid;
mes = new Message(pin,pout);
mm = new MyMessage();
iflog = false;
setCenter();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(722, 520);
// this.setLocation(300, 100);
this.setContentPane(getJContentPane());
this.setTitle("Customer");
}
public void setCenter(){
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width = screenSize.width;
int height = screenSize.height;
final int WIDTH= 722;
final int HEIGHT= 520;
int x=(width -WIDTH)/2;
int y=(height - HEIGHT)/2;
setLocation(x,y);
}
private void AllRestaurantView()
{
DefaultTableModel model = new DefaultTableModel()
{
public boolean isCellEditable(int row, int column) {
return false;
}
};
Vector data = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("餐館");
columnNames.addElement("restaurant_id");
model.setDataVector(data,columnNames);
restaurantview_jTable.setModel(model);
restaurantview_jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try{
mm.SetType("AllRestaurantView");
mm.SetNum(0);
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
int n = mm.GetNum()/2;
for(int i = 0; i < n; i++)
{
model.addRow(new Object[]{mm.GetMes(2*i),mm.GetMes(2*i+1)});
}
}
else if("false".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"No restaurant!");
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
private void FoodView()
{
DefaultTableModel model = new DefaultTableModel()
{
public boolean isCellEditable(int row, int column) {
return false;
}
};
Vector data = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("菜名");
columnNames.addElement("價格");
model.setDataVector(data,columnNames);
foodview_jTable.setModel(model);
foodview_jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
model2 = new DefaultTableModel()
{
public boolean isCellEditable(int row, int column) {
return false;
}
};
Vector data2 = new Vector();
Vector columnNames2 = new Vector();
columnNames2.addElement("點菜清單");
columnNames2.addElement("價格");
model2.setDataVector(data2,columnNames2);
myfood_jTable.setModel(model2);
myfood_jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try{
mm.SetType("FoodView");
mm.SetNum(1);
mm.SetMes(""+restaurantview_jTable.getValueAt(RowNumrestaurant, 1), 0);
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
int n = mm.GetNum()/2;
for(int i = 0; i < n; i++)
{
model.addRow(new Object[]{mm.GetMes(2*i),mm.GetMes(2*i+1)});
}
}
else if("false".equals(mm.GetType()))
{
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
private void Dine()
{
try{
int food = model2.getRowCount();
int num = 3+food*2;
mm.SetType("Dine");
mm.SetNum(num);
mm.SetMes(id, 0);
mm.SetMes(""+restaurantview_jTable.getValueAt(RowNumrestaurant, 1),1);
if(foodpaytransfer_jRadioButton.isSelected())
{
mm.SetMes("transfer", 2);
}
else
{
mm.SetMes("cash", 2);
}
for(int line = 0,i = 3;i < num;i+=2,line++)
{
mm.SetMes(""+myfood_jTable.getValueAt(line, 0), i);
mm.SetMes(""+myfood_jTable.getValueAt(line, 1), i+1);
}
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Order success!");
}
else if("customernoaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"You don't have an account!");
}
else if("restaurantnoaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"The restaurant doesn't have an account!");
}
else if("notenoughcash".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Your cash is inadequate!");
}
else if("notenoughtaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Your account is inadequate!");
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
private void SoftsellView()
{
DefaultTableModel model = new DefaultTableModel()
{
public boolean isCellEditable(int row, int column) {
return false;
}
};
Vector data = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("軟件銷售公司");
columnNames.addElement("softsellcorp_id");
model.setDataVector(data,columnNames);
softsellview_jTable.setModel(model);
softsellview_jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try{
mm.SetType("AllSoftSellView");
mm.SetNum(0);
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
int n = mm.GetNum()/2;
for(int i = 0; i < n; i++)
{
model.addRow(new Object[]{mm.GetMes(2*i),mm.GetMes(2*i+1)});
}
}
else if("false".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"No softsellcorp!");
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
private void SoftView()
{
DefaultTableModel model = new DefaultTableModel()
{
public boolean isCellEditable(int row, int column) {
return false;
}
};
Vector data = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("軟件名稱");
columnNames.addElement("軟件描述");
columnNames.addElement("價格");
model.setDataVector(data,columnNames);
softview_jTable.setModel(model);
softview_jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try{
mm.SetType("SoftView");
mm.SetNum(1);
mm.SetMes(""+softsellview_jTable.getValueAt(RowNumsoftsell, 1), 0);
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
int n = mm.GetNum()/3;
for(int i = 0; i < n; i++)
{
model.addRow(new Object[]{mm.GetMes(3*i),mm.GetMes(3*i+1),mm.GetMes(3*i+2)});
}
}
else if("false".equals(mm.GetType()))
{
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
private void Buy()
{
try{
mm.SetType("BuySoft");
mm.SetNum(5);
mm.SetMes(id, 0);
mm.SetMes(""+softsellview_jTable.getValueAt(RowNumsoftsell, 1),1);
mm.SetMes(""+softview_jTable.getValueAt(RowNumsoft, 0),2);
mm.SetMes(""+softview_jTable.getValueAt(RowNumsoft, 2),3);
if(transfer_jRadioButton.isSelected())
{
mm.SetMes("transfer", 4);
}
else
{
mm.SetMes("cash", 4);
}
mes.SendMessage(mm);
mes.GetMessage(mm);
if("true".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Buy success!");
}
else if("customernoaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"You don't have an account!");
}
else if("sellnoaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Softsell doesn't have an account!");
}
else if("notenoughcash".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Your cash is inadequate!");
}
else if("notenoughtaccount".equals(mm.GetType()))
{
JOptionPane.showMessageDialog(null,"Your account is inadequate!");
}
else
{
JOptionPane.showMessageDialog(null,"Error!");
}
}catch(Exception ie)
{
JOptionPane.showMessageDialog(null,"Network exception,please exit and log!");
}
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
RestraurantGroup = new ButtonGroup();
SoftGroup = new ButtonGroup();
note_jLabel = new JLabel();
note_jLabel.setBounds(new Rectangle(83, 68, 338, 18));
note_jLabel.setText("Please choose where to go.");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getPersonalbank(), null);
jContentPane.add(getBuy(), null);
jContentPane.add(getGotorestaurant(), null);
jContentPane.add(getMyrecord(), null);
jContentPane.add(getBankPanel(), null);
jContentPane.add(getSoftwarePanel(), null);
jContentPane.add(getRestaurantPanel(), null);
jContentPane.add(getBankenterPanel(), null);
jContentPane.add(getRegaccountPanel(), null);
jContentPane.add(note_jLabel, null);
jContentPane.add(getMyrecord_jPanel(), null);
SoftGroup.add(transfer_jRadioButton);
SoftGroup.add(cash_jRadioButton);
RestraurantGroup.add(foodpaytransfer_jRadioButton);
RestraurantGroup.add(foodpaycash_jRadioButton);
bankenterPanel.setVisible(false);
regaccountPanel.setVisible(false);
bankPanel.setVisible(false);
softwarePanel.setVisible(false);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -