📄 zhandianpnl.java
字号:
/*此类负责站点的增,删,该的界面规划与功能的实现*/
package pro;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class ZhandianPnl extends JPanel implements ActionListener
{
//JPanel jPanel1 = new JPanel();
//JPanel pnlXiuGai = new JPanel();
JButton btnXiuGai = new JButton();
JComboBox cboXiuGaiZiMu = new JComboBox(new Selebus().seleAZ());
JLabel labXiuZhan = new JLabel();
JComboBox cboXiuGaiMing = new JComboBox();
JLabel labXiuGeng = new JLabel();
JTextField txtGengXin = new JTextField();
//JPanel jPanel2 = new JPanel();
JButton btnChaRu = new JButton();
JLabel labCha = new JLabel();
JComboBox cboChaZiMu = new JComboBox(new Selebus().seleAZ());
JTextField txtChaRu = new JTextField();
// JPanel pnlShan = new JPanel();
JButton btnShan = new JButton();
JComboBox cboShanZiMu = new JComboBox(new Selebus().seleAZ());
JComboBox cboShanMing = new JComboBox();
MainFrame mmf;
public ZhandianPnl(MainFrame mf)
{
mmf=mf;
//contentPane = (JPanel) getContentPane();
this.setLayout(null);
setSize(new Dimension(585, 359));
this.setBorder(BorderFactory.createEtchedBorder());
this.setBounds(new Rectangle(22, 21, 534, 214));
this.setLayout(null);
//pnlXiuGai.setBorder(BorderFactory.createLineBorder(Color.black));
// pnlXiuGai.setBounds(new Rectangle(1, 0, 532, 111));
//pnlXiuGai.setLayout(null);
btnXiuGai.setBounds(new Rectangle(452, 180, 88, 25));
btnXiuGai.setForeground(new Color(0, 217, 0));
btnXiuGai.setText("修改站点");
cboXiuGaiZiMu.setBounds(new Rectangle(70, 140, 161, 25));
cboXiuGaiZiMu.setToolTipText("请选择要修改站点名的首字母!");
labXiuZhan.setBackground(new Color(0, 217, 0));
labXiuZhan.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
labXiuZhan.setForeground(new Color(0, 217, 0));
labXiuZhan.setText("站名:");
labXiuZhan.setBounds(new Rectangle(4, 180, 57, 25));
cboXiuGaiMing.setBounds(new Rectangle(70, 220, 159, 26));
cboXiuGaiMing.setToolTipText("请选择要修改的站点名!");
labXiuGeng.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
labXiuGeng.setForeground(new Color(0, 217, 0));
labXiuGeng.setText("更新为:");
labXiuGeng.setBounds(new Rectangle(230, 180, 62, 30));
txtGengXin.setText("");
txtGengXin.setBounds(new Rectangle(277, 180, 152, 26));
txtGengXin.setToolTipText("请输入修改后的站点名!");
// this.setBorder(BorderFactory.createLineBorder(Color.black));
// this.setBounds(new Rectangle(1, 108, 532, 55));
// this.setLayout(null);
btnChaRu.setBounds(new Rectangle(277, 70, 85, 25));
btnChaRu.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnChaRu.setForeground(new Color(0, 217, 0));
btnChaRu.setText("新增站点");
labCha.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
labCha.setForeground(new Color(0, 217, 0));
labCha.setText("新增站点名:");
labCha.setToolTipText("输入要增加的站点名!即可根据站名首字母,添加到数据库表中的相应位置!");
labCha.setBounds(new Rectangle(4, 70, 70, 27));
cboChaZiMu.setBounds(new Rectangle(47, 400, 162, 26));
txtChaRu.setText("");
txtChaRu.setBounds(new Rectangle(70, 70, 157, 26));
txtChaRu.setToolTipText("请输入要增加的站点名!");
// this.setBorder(BorderFactory.createLin5eBorder(Color.black));
// this.setBounds(new Rectangle(1, 160, 532, 54));
// this.setLayout(null);
btnShan.setBounds(new Rectangle(452, 330, 85, 25));
btnShan.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnShan.setForeground(new Color(0, 217, 0));
btnShan.setText("删除站点");
cboShanZiMu.setBounds(new Rectangle(70, 330, 164, 25));
cboShanZiMu.setToolTipText("请选择要删除站点的首字母!");
cboShanMing.setBounds(new Rectangle(277, 330, 159, 25));
cboShanMing.setToolTipText("请选择要删除站点的名字!");
// this.add(jPanel1);
this.add(labXiuZhan);
this.add(txtGengXin);
this.add(btnXiuGai);
this.add(cboXiuGaiMing);
this.add(labXiuGeng);
this.add(cboXiuGaiZiMu);
this.add(btnShan);
this.add(cboShanMing);
this.add(cboShanZiMu);
// this.add(cboChaZiMu);
this.add(txtChaRu);
this.add(labCha);
this.add(btnChaRu);
btnChaRu.setActionCommand("btnChaRu");
btnChaRu.addActionListener(this);
btnXiuGai.setActionCommand("btnXiuGai");
btnXiuGai.addActionListener(this);
cboShanZiMu.setActionCommand("cboShanZiMu");
cboShanZiMu.addActionListener(this);
btnShan.setActionCommand("btnShan");
btnShan.addActionListener(this);
cboShanMing.setActionCommand("cboShanMing");
cboShanMing.addActionListener(this);
cboXiuGaiZiMu.setActionCommand("cboXiuGaiZiMu");
cboXiuGaiZiMu.addActionListener(this);
}
public void actionPerformed(java.awt.event.ActionEvent ae)
{
String ste=ae.getActionCommand();
String strAZ="";
if(ste.equals("cboXiuGaiZiMu"))
{
strAZ=(String)(cboXiuGaiZiMu.getSelectedItem());
Vector vectorLu=new Selebus().selelook(strAZ);
System.out.println(strAZ);
javax.swing.DefaultComboBoxModel dcb=new DefaultComboBoxModel(vectorLu);
cboXiuGaiMing.setModel(dcb);
}
if(ste.equals("cboShanZiMu"))
{
String strxx=(String)(cboShanZiMu.getSelectedItem());
Vector vectorLu=new Selebus().selelook(strxx);
javax.swing.DefaultComboBoxModel dfdf=new DefaultComboBoxModel(vectorLu);
cboShanMing.setModel(dfdf);
}
if(ste.equals("btnXiuGai"))
{
String es=(String)(cboXiuGaiMing.getSelectedItem());
System.out.println ("txtgengxing"+txtGengXin.getText());
if(es.length()>0&&txtGengXin.getText().length()>0)
{
if(new BusXiuGai().Zhanupdate(es,txtGengXin.getText()))
{
//Vector ve=sel
//mmf.pnlCha.cboZhan.setModel();
JOptionPane.showMessageDialog(this,"更新成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(this,"更新失败!","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
else
{
JOptionPane.showMessageDialog(this,"请选择或输入站点" ,"提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
}
if(ste.equals("btnChaRu"))
{
String az=(String)cboChaZiMu.getSelectedItem();
if(txtChaRu.getText().length()>0 && az.length()>0)
{
if(new BusXiuGai().Zhaninsert(txtChaRu.getText().trim()))
{
JOptionPane.showMessageDialog(this,"成功插入!" ,"提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(this,"插入失败!" ,"提示",JOptionPane.INFORMATION_MESSAGE);
}
}
else
{
JOptionPane.showMessageDialog(this,"请选择字母或填写站点名" ,"提示",JOptionPane.INFORMATION_MESSAGE);
}
}
if(ste.equals("btnShan"))
{
String att=(String)cboShanMing.getSelectedItem();
if(new BusXiuGai().Zhandelete(att))
{
JOptionPane.showMessageDialog(this,"删除成功!" ,"提示",JOptionPane.INFORMATION_MESSAGE);
// String strxx=(String)(cboShanZiMu.getSelectedItem());
// Vector vectorLu=new Selebus().selelook(strxx);
//javax.swing.DefaultComboBoxModel dfdf=new DefaultComboBoxModel(vectorLu);
//String strShanMing=(String)();
cboShanMing.removeItem(att);
mmf.pnlCha.cboZhan2.removeItem(att);
mmf.pnlCha.cboQi2.removeItem(att);
mmf.pnlCha.cboZhong2.removeItem(att);
//cboShanMing.setModel();
}
else
{
JOptionPane.showMessageDialog(this,"删除不成功!" ,"提示",JOptionPane.INFORMATION_MESSAGE);
}
}
}
public void paintComponent(Graphics g)//传一个画笔进来!
{
javax.swing.ImageIcon ii = new ImageIcon("img/shanZhanXiuGai.jpg");//把图片读出来!
g.drawImage(ii.getImage(), 0, 0, this);//画画,定位置!
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -