sahadat49

control.in.acion

Dec 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package conrol.in.action;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Container;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPasswordField;
  11. import javax.swing.JTextField;
  12.  
  13. public class ControlInAction {
  14.  
  15. public static void main(String[] args) {
  16. ABC j = new ABC();
  17. j.setVisible(true);
  18. j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19. j.setBounds(400, 300, 500, 500);
  20. j.setTitle("Java SWING Examples");
  21. }
  22.  
  23. }
  24.  
  25. class ABC extends JFrame {
  26.  
  27. private Container c;
  28. private JLabel j1, j2;
  29. private JTextField tf1;
  30. private JButton b1, b2, b3;
  31.  
  32. ABC() {
  33.  
  34. c = this.getContentPane();
  35. c.setLayout(null);
  36. c.setBackground(Color.WHITE);
  37.  
  38. j1 = new JLabel("Control in action in JButton");
  39. j1.setBounds(150, 50, 200, 50);
  40. c.add(j1);
  41.  
  42. tf1 = new JTextField();
  43. tf1.setBounds(150, 300, 150, 20);
  44. c.add(tf1);
  45.  
  46. b1 = new JButton("OK");
  47. b1.setBounds(100, 150, 60, 20);
  48. c.add(b1);
  49.  
  50. b2 = new JButton("Submit");
  51. b2.setBounds(170, 150, 90, 20);
  52. c.add(b2);
  53.  
  54. b3 = new JButton("Cancle");
  55. b3.setBounds(280, 150, 80, 20);
  56. c.add(b3);
  57.  
  58. Handler h = new Handler();
  59.  
  60. b1.addActionListener(h);
  61. b2.addActionListener(h);
  62. b3.addActionListener(h);
  63.  
  64. }
  65.  
  66. class Handler implements ActionListener {
  67.  
  68. @Override
  69. public void actionPerformed(ActionEvent e) {
  70.  
  71. if (e.getSource() == b1) {
  72. tf1.setText("OK button clicked");
  73. } else if (e.getSource() == b2) {
  74. tf1.setText("Submit button clicked");
  75. } else if (e.getSource() == b3) {
  76. tf1.setText("Cancle button clicked");
  77. }
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment