📄 requestpane.java
字号:
/* Copyright 2002 MonkeyStar SoftWare, Inc. All rights reserved.
* The Start of the ATM Project for Product Company
* @author Wujun, Student Number:09800134
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.BorderFactory.*;
import javax.swing.border.*;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.io.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.table.*;
public class RequestPane extends JPanel implements ListSelectionListener{
Component f;
RequestPane This = this;
Socket SrvSock;
Goods CardGoods;
ListSelectionModel selectMode =null;
String[] s = {"南瓜","柚子","葡萄","弥猴桃","流连","水蜜桃","仙人果","凤梨","荔枝","草莓","蕃茄","西瓜"};
Vector m_Request;
Font fontword = new Font("楷体_GB2312",Font.BOLD,15);
ImageIcon[] icons = new ImageIcon[12];
RequestModel tm=new RequestModel();
JTable tableRequest=new JTable(tm);
JScrollPane tbScroll = new JScrollPane(tableRequest);
private ActionListener listener=new ActionResponse();
JLabel l1= new JLabel("售货机地址:");
JLabel l2= new JLabel("发送商品名:");
JLabel l3= new JLabel("发货量:");
JLabel l4= new JLabel("送货人:");
JTextField txtSrvIP= new JTextField(10);
JTextField txtAmount= new JTextField(10);
JComboBox Combo1;
JComboBox ComboSend = new JComboBox();
JButton btSend = new JButton("发 货",new ImageIcon(".\\img\\sendgood.jpg"));
public void SetPosition()
{
tbScroll.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black,1),"Auto Service Requirement",TitledBorder.CENTER,TitledBorder.TOP));
l1.setBounds(0,230,100,30);
l2.setBounds(0,260,100,30);
l3.setBounds(240,235,80,20);
l4.setBounds(240,265,80,20);
l1.setFont(fontword);
l2.setFont(fontword);
l3.setFont(fontword);
l4.setFont(fontword);
l1.setForeground(Color.blue);
l2.setForeground(Color.blue);
l3.setForeground(Color.blue);
l4.setForeground(Color.blue);
txtSrvIP.setBounds(100,235,115,20);
txtAmount.setBounds(300,235,80,20);
txtSrvIP.setFont(fontword);
txtAmount.setFont(fontword);
Combo1.setBounds(100,265,115,25);
txtSrvIP.setText("211.65.34.26");
ComboSend.setBounds(300,265,80,25);
ComboSend.setFont(new Font("楷体_GB2312",Font.BOLD,14));
btSend.setBounds(400,250,100,30);
btSend.setFont(fontword);
btSend.setForeground(Color.blue);
btSend.addActionListener(listener);
this.add(Combo1);
this.add(ComboSend);
this.add(l1);
this.add(l2);
this.add(l3);
this.add(l4);
this.add(txtSrvIP);
this.add(txtAmount);
this.add(btSend);
}
class ActionResponse implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (e.getSource()==btSend)
{
String title = "送货提示:";
int type = JOptionPane.INFORMATION_MESSAGE;
String[] options={"送货","取消"};
int optionType=JOptionPane.YES_NO_OPTION;
int messageType=JOptionPane.QUESTION_MESSAGE;
String message = "商品名: "+((ItemObj)Combo1.getSelectedItem()).name
+"\n提货数量:"+txtAmount.getText()
+"\n送货员:"+ComboSend.getSelectedItem().toString()
+"\n自动售货机地址: "+txtSrvIP.getText()
+"\n立即前去送货吗?";
int result = JOptionPane.showOptionDialog(f,message, title, optionType,messageType,null,options,options[1]);
if (result == JOptionPane.YES_OPTION)
{
try{
SrvSock = new Socket((new ReadConfig()).getAutoSrvIP(),6000);
SendThread st = new SendThread(SrvSock,((ItemObj)Combo1.getSelectedItem()).name,Integer.parseInt(txtAmount.getText()),f,This,CardGoods);
st.start();}
catch(IOException exp)
{}
}
}
}
}
public RequestPane(Component ComponentF,Goods goods)
{
this.setLayout(null);
f=ComponentF;
CardGoods=goods;
ItemObj[] obj = new ItemObj[12];
for(int i=0; i < 12; i++)
{
icons[i] = new ImageIcon(".\\img\\small\\list"+String.valueOf(i+1)+".jpg");
obj[i] = new ItemObj(s[i],icons[i]);
}
Combo1= new JComboBox(obj);
Combo1.setRenderer(new ACellRenderer());
Combo1.setMaximumRowCount(6);
SetPosition();
tbScroll.setBounds(0,0,510,220);
tableRequest.setRowHeight(30);
getRequestDB();
tableRequest.getColumnModel().getColumn(0).setPreferredWidth(10);
tableRequest.getColumnModel().getColumn(1).setPreferredWidth(20);
tableRequest.getColumnModel().getColumn(2).setPreferredWidth(50);
tableRequest.getColumnModel().getColumn(3).setPreferredWidth(50);
tableRequest.getColumnModel().getColumn(4).setPreferredWidth(30);
tableRequest.getColumnModel().getColumn(5).setPreferredWidth(30);
tableRequest.getColumnModel().getColumn(6).setPreferredWidth(30);
selectMode = tableRequest.getSelectionModel();
selectMode.addListSelectionListener(this);
LoadSender();
this.add(tbScroll);
}
public void valueChanged(ListSelectionEvent e1)
{
String tmpIP = "";
String tmpNeed="";
String tmpProduct="";
int[] rows = tableRequest.getSelectedRows();
int[] columns = tableRequest.getSelectedColumns();
for (int i=0; i<rows.length; i++) {
for (int j=0; j<columns.length; j++)
{
tmpIP = (String)tableRequest.getValueAt(rows[i], 2);
tmpNeed=tableRequest.getValueAt(rows[i],5).toString();
tmpProduct= (String)tableRequest.getValueAt(rows[i], 1);
}
}
txtAmount.setText(tmpNeed);
txtSrvIP.setText(tmpIP);
for (int n=0;n<Combo1.getItemCount();n++)
{
if (((ItemObj)Combo1.getItemAt(n)).name.equals(tmpProduct))
Combo1.setSelectedIndex(n);
}
}
public void LoadSender()
{
ComboSend.removeAllItems();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:company","","");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("SELECT * FROM DACL WHERE Role='送货员'");
while(r.next())
{
ComboSend.addItem(r.getString("Name"));
}
s.close();
} catch(SQLException Exp)
{System.out.println(Exp.toString()); }
catch(ClassNotFoundException Exp)
{JOptionPane.showMessageDialog(f, Exp.toString(), "错误:", JOptionPane.INFORMATION_MESSAGE);}
catch(Exception Exp)
{}
}
public void Msgbox(String msg)
{
JOptionPane.showMessageDialog(f, msg, "提示:", JOptionPane.INFORMATION_MESSAGE);
}
public void getRequestDB()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:company","","");
Statement s = c.createStatement();
m_Request=new Vector();
ResultSet r = s.executeQuery("SELECT * FROM request");
while(r.next())
{
Request request = new Request();
request.ProductID=r.getString("ProductID");
request.ProName=r.getString("Product");
request.IPAddress=r.getString("RequestIP");
request.Time=r.getString("RequestTime");
request.Amount=r.getInt("RequestNum");
request.NowHave=r.getInt("NowHave");
m_Request.addElement(request);
}
s.close();
tm.setItem(m_Request);
}
catch(SQLException Exp)
{System.out.println(Exp.toString()); }
catch(ClassNotFoundException Exp)
{JOptionPane.showMessageDialog(f, Exp.toString(), "错误:", JOptionPane.INFORMATION_MESSAGE);}
catch(Exception Exp)
{JOptionPane.showMessageDialog(f, Exp.toString(), "错误:", JOptionPane.INFORMATION_MESSAGE);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -