This post is 'How to using JCheckBox'.
If You run SWING, can see below picture.
I made 1 JCheckBox.
And change the name.
'Variable' is variable name in Source.
'text' is check box name in GUI.
Go to 'Source'
serverSWING.java
- private JFrame frame;
- private JTextField portNum;
- private JButton btnServerOpen,btnClear,btnSend;
- ServerSocket ss;
- Socket socket;
- InetAddress ia;
- Thread server;
- public static boolean disconnected=true;
- private JEditorPane sendText;
- public static boolean echoEnable=false;
- private JCheckBox checkEcho;
- private JScrollPane scrollPane;
- }
Line 14 : declared JCheckBox.
This is initailize.
- checkEcho.setBounds(493, 375, 119, 23);
- frame.getContentPane().add(checkEcho);
- checkEcho.addItemListener(this);
This is auto adding listener code.
- @Override
- if(e.getSource()==checkEcho){
- echoEnable=true;
- else
- echoEnable=false;
- checkEcho();
- }
- }
Line 4: 'ItemEvent.SELECTED' mean checked JCheckBox.
No comments:
Post a Comment