⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 restrjpanel.java

📁 餐馆服务的客户端程序
💻 JAVA
字号:
/* * restrJPanel.java * * Created on 2008年9月1日, 上午9:23 */package restr;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.*;import java.util.Properties;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author  Administrator */public class restrJPanel extends javax.swing.JPanel {    /** Creates new form restrJPanel */    public restrJPanel() {        initComponents();    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        jLabel3 = new javax.swing.JLabel();        jLabel4 = new javax.swing.JLabel();        jLabel5 = new javax.swing.JLabel();        diancan1 = new javax.swing.JTextField();        diancan2 = new javax.swing.JTextField();        diancan3 = new javax.swing.JTextField();        diancan4 = new javax.swing.JTextField();        jButton1 = new javax.swing.JButton();        jLabel1.setText("可乐(费用10,减少10疲劳值)");        jLabel2.setText("汉堡(费用20,减少20疲劳值)");        jLabel3.setText("披萨(费用50,减少50疲劳值)");        jLabel4.setText("套餐(费用100,减少200疲劳值)");        jLabel5.setText("数量");        diancan1.setText("0");        diancan1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                diancan1ActionPerformed(evt);            }        });        diancan2.setText("0");        diancan2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                diancan2ActionPerformed(evt);            }        });        diancan3.setText("0");        diancan3.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                diancan3ActionPerformed(evt);            }        });        diancan4.setText("0");        jButton1.setText("点餐");        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);        this.setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addGap(32, 32, 32)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)                        .addComponent(diancan3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)                        .addComponent(diancan2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)                        .addComponent(diancan1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)                        .addComponent(diancan4, javax.swing.GroupLayout.Alignment.LEADING)))                .addGap(37, 37, 37))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGap(26, 26, 26)                .addComponent(jLabel5)                .addGap(18, 18, 18)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel1)                    .addComponent(diancan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel2)                    .addComponent(diancan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel3)                    .addComponent(diancan3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel4)                    .addComponent(diancan4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(18, 18, 18)                .addComponent(jButton1)                .addContainerGap(73, Short.MAX_VALUE))        );    }// </editor-fold>//GEN-END:initComponentsprivate void diancan3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diancan3ActionPerformed// TODO add your handling code here:}//GEN-LAST:event_diancan3ActionPerformedprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed    int a=Integer.parseInt(diancan1.getText());    int b=Integer.parseInt(diancan2.getText());    int c=Integer.parseInt(diancan3.getText());    int d=Integer.parseInt(diancan4.getText());          if(a<0||b<0||c<0||d<0)    {       //输出出错信息    }    else if(a+b+c+d==0)    {        //输出出错信息    }    else    {        //开始打包传送请求        Properties pro=new Properties();        Properties p=new Properties();        pro.setProperty("type", "diancan");    ///////////////////////////////////////////////////////////////////////////////////////////////加入id        pro.setProperty("m",String.valueOf(10*a+20*b+50*c+100*d) );        pro.setProperty("p", String.valueOf(10*a+20*b+50*c+200*d));                //开始建立连接        String ip="127.0.0.1";        int port=10000;        Socket s = null;        OutputStream out = null;        InputStream in=null;                  try {                s = new Socket(ip, port);                                        out = s.getOutputStream();                in = s.getInputStream();                         pro.store(out, "");                               p.load(in);                                if(p.getProperty("type").matches("rok"))                {                    //输出成功信息                }                else                {                    //输出错误信息                }                                                //关闭连接                in.close();                out.close();                s.close();                                            }         catch (IOException ex)             {                Logger.getLogger(restrJPanel.class.getName()).log(Level.SEVERE, null, ex);            }                                      }}//GEN-LAST:event_jButton1ActionPerformedprivate void diancan2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diancan2ActionPerformed// TODO add your handling code here:}//GEN-LAST:event_diancan2ActionPerformedprivate void diancan1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diancan1ActionPerformed// TODO add your handling code here:}//GEN-LAST:event_diancan1ActionPerformed    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JTextField diancan1;    private javax.swing.JTextField diancan2;    private javax.swing.JTextField diancan3;    private javax.swing.JTextField diancan4;    private javax.swing.JButton jButton1;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -