📄 modifydia.java
字号:
package util3;import javax.swing.*;import java.awt.*;import util2.*;import util4.*;import java.awt.event.*;import util5.*;public class ModifyDia extends JDialog{ JPanel jPanel1 = new JPanel(); GridBagLayout gridBagLayout1 = new GridBagLayout(); JLabel nameLab = new JLabel(); JTextField renameTf = new JTextField(); JLabel goalLab = new JLabel(); JButton okBut = new JButton(); JButton cancelBut = new JButton(); JLabel nulLab = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); JTextArea goalTa = new JTextArea(); Messager mesg; YorNListener listen; boolean taNotify=false; private JScrollPane jScrollPane2 = new JScrollPane(); private JLabel jLabel1 = new JLabel(); private JTextArea remarkTA = new JTextArea(); private JLabel jLabel2 = new JLabel(); public ModifyDia(Frame frame,String title,boolean modal) { super(frame,title,modal); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jPanel1.setLayout(gridBagLayout1); nameLab.setFont(new java.awt.Font("Dialog", 1, 14)); nameLab.setText("r : "); goalLab.setFont(new java.awt.Font("Dialog", 1, 14)); goalLab.setText("Value : "); okBut.setActionCommand("okBut"); okBut.setText("OK"); cancelBut.setActionCommand("cancelBut"); cancelBut.setText("Cancel"); nulLab.setFont(new java.awt.Font("Dialog", 1, 14)); nulLab.setText(" "); goalTa.setCaretColor(SystemColor.activeCaption); goalTa.setForeground(SystemColor.desktop); goalTa.setFont(new java.awt.Font("SansSerif", 0, 13)); renameTf.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(KeyEvent e) {//System.out.println("typed"); renameTf_released(e); } }); renameTf.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ okBut.doClick(); } }); jLabel1.setText(" "); jScrollPane1.setPreferredSize(new Dimension(40, 23)); jLabel2.setFont(new java.awt.Font("Dialog", 1, 14)); jLabel2.setText("Remark :"); this.getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.add(jScrollPane1, new GridBagConstraints(1, 1, 2, 3, 1.0, 0.6 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.BOTH, new Insets(0, -37, 5, 3), 0, 41)); jPanel1.add(nulLab, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jScrollPane2, new GridBagConstraints(1, 4, 2, 1, 1.0, 0.3 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.BOTH, new Insets(0, -37, 0, 3), 0, 47)); jScrollPane2.getViewport().add(remarkTA, null); jPanel1.add(jLabel1, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 57, 5)); jPanel1.add(okBut, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, -28, 0, 33), 19, 0)); jPanel1.add(cancelBut, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(nameLab, new GridBagConstraints(0, 0, 1, 1, 0.3, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(goalLab, new GridBagConstraints(0, 1, 1, 1, 0.2, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 1, 0, 25), 0, 0)); jPanel1.add(jLabel2, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(-1, -1, 1, 37), 0, 0)); jPanel1.add(renameTf, new GridBagConstraints(1, 0, 2, 1, 0.7, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, -37, 0, 80), 0, 0)); jScrollPane1.getViewport().add(goalTa, null); renameTf.setColumns(15); setBounds(270,190,360,290); okBut.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ /*String str=renameTf.getText(); if(str.length()==0) return ; mesg=new Messager(str); if(selfEditCB.isSelected()){ String s=goalTa.getText(); mesg.setContent(s); ModifyDia.this.setVisible(false); listen.gotYes(true); } else{ mesg.makeContent(); ModifyDia.this.setVisible(false); listen.gotYes(true); } selfEditCB.setSelected(false);*/ String str=renameTf.getText(); if(str.length()==0) return; mesg.setName(str); mesg.setContent(goalTa.getText()); mesg.setAttMsg(remarkTA.getText()); ModifyDia.this.setVisible(false); listen.gotYes(YorNListener.yes); } }); cancelBut.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ ModifyDia.this.setVisible(false); listen.gotYes(YorNListener.no); } }); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { ModifyDia.this.setVisible(false); listen.gotYes(YorNListener.cancel); } }); } public void setNameRow(String lab,Messager m){ this.nameLab.setText(lab); this.renameTf.setText(m.getName()); this.goalTa.setText(m.getContent()); this.remarkTA.setText(m.getAttMsg()); this.mesg=m; if("Name : "==(lab.intern())) taNotify=true; else taNotify=false; } public void showIt(String s){ this.setTitle(s); this.goalTa.setEditable(true); this.setVisible(true); } public void showIt(String title,boolean state){ this.setTitle(title); this.goalTa.setEditable(state); this.setVisible(true); } public void addYorNListener(YorNListener l){ this.listen=l; } public Messager getMesg(){return this.mesg;} void renameTf_released(KeyEvent e) { if(this.taNotify){//System.out.println("tt"); String s=null; if((s=renameTf.getText().trim()).length()!=0){ this.goalTa.setText(Messager.makeContent(s)); } } } public static void main(String[] arg){ JFrame jf=new JFrame("try"); ModifyDia rp=new ModifyDia(jf,"Rename",false); jf.setBounds(200,200,200,200); jf.show(); rp.show(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -