【2】JAVA---地址App小软件(ListPanel.class)(表现层)

这个是表现层的主界面。

【2】JAVA---地址App小软件(ListPanel.class)(表现层)

/*
* ListPanel.java
*
*/ package cn.hncu.addr.ui; import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane; import cn.hncu.addr.business.AddrBusiness; /**
*
* @author __chx__
*/
public class ListPanel extends javax.swing.JPanel {
/** Creates new form ListPanel */
private JFrame mainFrame = null;
private JLabel jlbFindAddress = new javax.swing.JLabel(); public ListPanel(JFrame mainFrame) {
this.mainFrame = mainFrame;
initComponents();
myInitData();
} public ListPanel(JFrame mainFrame, Object[] objs) {
this.mainFrame = mainFrame;
initComponents();
jListAddress.setListData(objs); jlbFindAddress
.setText("\u67e5\u627e\u5230\u7684\u5730\u5740\u4fe1\u606f\uff1a");
add(jlbFindAddress);
jlbFindAddress.setBounds(40, 50, 125, 17);
} private void myInitData() {
AddrBusiness set = new AddrBusiness();
Object obj[] = set.getAll();
jListAddress.setListData(obj);
} /**
* 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.
*/
private JList<String> getListAddress() {
return jListAddress;
} private void initComponents() {
jLabelApp = new javax.swing.JLabel();
jbtnAdd = new javax.swing.JButton();
jbtnChange = new javax.swing.JButton();
jbtnDelete = new javax.swing.JButton();
jbtnFind = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jListAddress = new javax.swing.JList();
jLabel1 = new javax.swing.JLabel();
jToggleButton1 = new javax.swing.JToggleButton(); setPreferredSize(new java.awt.Dimension(800, 600));
setLayout(null); jLabelApp.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 36));
jLabelApp.setForeground(new java.awt.Color(255, 0, 0));
jLabelApp.setText(" \u5730\u5740\u4fe1\u606fApp");
add(jLabelApp);
jLabelApp.setBounds(240, 20, 263, 47); jbtnAdd.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
jbtnAdd.setForeground(new java.awt.Color(102, 102, 255));
jbtnAdd.setText("\u6dfb\u52a0\u5730\u5740");
jbtnAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnAddActionPerformed(evt);
}
});
add(jbtnAdd);
jbtnAdd.setBounds(120, 360, 120, 60); jbtnChange.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
jbtnChange.setForeground(new java.awt.Color(102, 102, 255));
jbtnChange.setText("\u4fee\u6539\u5730\u5740");
jbtnChange.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnChangeActionPerformed(evt);
}
});
add(jbtnChange);
jbtnChange.setBounds(120, 460, 120, 60); jbtnDelete.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
jbtnDelete.setForeground(new java.awt.Color(102, 102, 255));
jbtnDelete.setText("\u5220\u9664\u5730\u5740");
jbtnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnDeleteActionPerformed(evt);
}
});
add(jbtnDelete);
jbtnDelete.setBounds(470, 460, 120, 60); jbtnFind.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
jbtnFind.setForeground(new java.awt.Color(102, 102, 255));
jbtnFind.setText("\u67e5\u627e\u5730\u5740");
jbtnFind.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnFindActionPerformed(evt);
}
});
add(jbtnFind);
jbtnFind.setBounds(470, 360, 120, 60); jListAddress.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
jListAddress.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "" }; public int getSize() {
return strings.length;
} public Object getElementAt(int i) {
return strings[i];
}
});
jScrollPane1.setViewportView(jListAddress); add(jScrollPane1);
jScrollPane1.setBounds(40, 70, 700, 270); jLabel1.setText(" \u9648\u6d69\u7fd4");
add(jLabel1);
jLabel1.setBounds(700, 510, 60, 17); jToggleButton1.setText("\u9000\u51fa");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
add(jToggleButton1);
jToggleButton1.setBounds(680, 410, 80, 50);
} private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
} private void jbtnFindActionPerformed(java.awt.event.ActionEvent evt) {
mainFrame.setContentPane(new QueryPanel(mainFrame));
mainFrame.validate();
} private void jbtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
if (jListAddress.getSelectedValue() == null) {
JOptionPane.showMessageDialog(this, "未选中地址!无法删除,请重新选择!");
} else {
mainFrame.setContentPane(new DeletePanel(mainFrame,
(String) jListAddress.getSelectedValue()));
mainFrame.validate();
}
} private void jbtnChangeActionPerformed(java.awt.event.ActionEvent evt) {
if (jListAddress.getSelectedValue() == null) {
JOptionPane.showMessageDialog(this, "未选中地址!无法修改,请重新选择!");
} else {
mainFrame.setContentPane(new UpdatePanel(mainFrame,
(String) jListAddress.getSelectedValue()));
mainFrame.validate();
}
} private void jbtnAddActionPerformed(java.awt.event.ActionEvent evt) {
// System.out.println("aaa");
mainFrame.setContentPane(new AddPanel(mainFrame));
mainFrame.revalidate();
} private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabelApp;
private javax.swing.JList jListAddress;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JButton jbtnAdd;
private javax.swing.JButton jbtnChange;
private javax.swing.JButton jbtnDelete;
private javax.swing.JButton jbtnFind; }
上一篇:降低磁盘IO使Oracle性能优化(转)


下一篇:ThinkPHP3.2 分页实现