在awt中如何来设计灰色按钮
提示: 作者被禁止或删除 内容自动屏蔽
public class Test1 extends javax.swing.JFrame { private JButton jButton1; private JButton jButton3; private JButton jButton2; /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Test1 inst = new Test1(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public Test1() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().add(getJButton2(), BorderLayout.CENTER); getContentPane().add(getJButton3(), BorderLayout.SOUTH); getContentPane().add(getJButton1(), BorderLayout.NORTH); pack(); setSize(100, 120); } catch (Exception e) { e.printStackTrace(); } } private JButton getJButton1(){ if(jButton1==null){ jButton1 = new JButton(); jButton1.setText("jButton1"); jButton1.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { getJButton2().setEnabled(false); }}); } return jButton1; } private JButton getJButton2() { if (jButton2 == null) { jButton2 = new JButton(); jButton2.setText("jButton2"); jButton2.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { getJButton1().setEnabled(false); }}); } return jButton2; } private JButton getJButton3() { if (jButton3 == null) { jButton3 = new JButton(); jButton3.setText("jButton3"); jButton3.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { getJButton2().setEnabled(true); getJButton1().setEnabled(true); }}); } return jButton3; } }