📄 addedusers.java
字号:
/* * AddedUsers.java * * Created on 2008年10月28日, 下午1:50 */package ipmsg.gui;import ipmsg.etc.UtilityGlobal;import ipmsg.etc.GlobalVar;/** * * @author Noeru */public class AddedUsers extends javax.swing.JFrame { /** Creates new form AddedUsers */ public AddedUsers() { GlobalVar.WINDOW_REG.add("addedUser"); initComponents(); this.setTitle("管理好友"); this.guiManual.setListData(GlobalVar.ADDED_USER); this.refreshGui("当前共有 "+GlobalVar.ADDED_USER.size()+ " 好友!"); } /** 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() { jPanel4 = new javax.swing.JPanel(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); guiManual = new javax.swing.JList(); jPanel3 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); warning = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setMinimumSize(new java.awt.Dimension(314, 452)); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jButton2.setText("删除"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("清空"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText("关闭"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4) .addContainerGap()) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addContainerGap(249, Short.MAX_VALUE) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addGap(18, 18, 18) .addComponent(jButton4) .addContainerGap()) ); getContentPane().add(jPanel4, java.awt.BorderLayout.LINE_END); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("好友列表")); jScrollPane1.setViewportView(guiManual); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE) ); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("添加")); jTextField1.setText("在此输入ip"); jTextField1.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { jTextField1MousePressed(evt); } }); jButton1.setText("添加"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap()) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); getContentPane().add(jPanel3, java.awt.BorderLayout.PAGE_START); warning.setText(" 状态栏"); getContentPane().add(warning, java.awt.BorderLayout.PAGE_END); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-314)/2, (screenSize.height-452)/2, 314, 452); }// </editor-fold>//GEN-END:initComponentsprivate void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed// TODO add your handling code here: if (this.guiManual.getSelectedValues().length == 0) { this.warning.setText("请选择好友记录!"); return; } int tmpSelected[] = this.guiManual.getSelectedIndices(); for (int i = tmpSelected.length - 1; i >= 0; i--) { GlobalVar.ADDED_USER.remove(tmpSelected[i]); } this.refreshGui("删除 "+tmpSelected.length+" 个好友!");}//GEN-LAST:event_jButton2ActionPerformedprivate void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed// TODO add your handling code here: if (!UtilityGui.confirm(this, "清空好友", "您确定要清空好友列表?")) { return; } GlobalVar.ADDED_USER.clear(); this.refreshGui("您清空了好友列表");}//GEN-LAST:event_jButton3ActionPerformedprivate void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed// TODO add your handling code here: this.exit();}//GEN-LAST:event_jButton4ActionPerformedprivate void jTextField1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1MousePressed// TODO add your handling code here: this.jTextField1.setText("");}//GEN-LAST:event_jTextField1MousePressedprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed// TODO add your handling code here: String tmpIp =jTextField1.getText().trim(); this.jTextField1.setText("在此输入ip"); if (tmpIp == null || tmpIp.equals("")) { this.warning.setText("请输入好友ip地址!"); return; } if (!UtilityGlobal.isIP(tmpIp)) { this.warning.setText("请输入正确的ip地址!"); return; } if (GlobalVar.ADDED_USER.contains(tmpIp)) { this.warning.setText("该IP地址已经存在于好友列表!"); return; } GlobalVar.ADDED_USER.add(tmpIp); this.refreshGui("将好友 \"" + tmpIp + " \"添加至好友列表!");}//GEN-LAST:event_jButton1ActionPerformedprivate void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing// TODO add your handling code here: this.exit();}//GEN-LAST:event_formWindowClosing /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new AddedUsers().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList guiManual; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField jTextField1; private javax.swing.JLabel warning; // End of variables declaration//GEN-END:variables private void refreshGui(String str){ this.guiManual.setListData(GlobalVar.ADDED_USER); this.warning.setText(str); } private void exit(){ GlobalVar.WINDOW_REG.remove("addedUser"); this.dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -