Advertisement
Guest User

ex1

a guest
Dec 12th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2. package example;
  3.  
  4. import java.awt.Color;
  5. import javax.swing.GroupLayout;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.JTextField;
  10.  
  11. public class Example {
  12.  
  13. public JFrame frame;
  14. public JPanel panel;
  15. public JButton btn;
  16. public JTextField txt;
  17.  
  18. public Example()
  19. {
  20. init();
  21. }
  22.  
  23. void init()
  24. {
  25. frame = new JFrame();
  26. frame.setVisible(true);
  27. frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  28. frame.setSize(3 * 100, 3 * 100);
  29. frame.setLocation(350, 50);
  30. frame.setBackground(Color.BLUE);
  31.  
  32. panel = new JPanel();
  33. frame.add(panel);
  34. panel.setVisible(true);
  35. //panel.setBackground(Color.GRAY);
  36. panel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  37. panel.setPreferredSize(new java.awt.Dimension(100, 100));
  38.  
  39. btn = new JButton();
  40. panel.add(btn);
  41. btn.setSize(150, 50);
  42. btn.setVisible(true);
  43. btn.setLocation(100, 180);
  44. btn.setText("Button");
  45.  
  46. txt = new JTextField();
  47. panel.add(txt);
  48. txt.setSize(50, 50);
  49. txt.setVisible(true);
  50. txt.setText("Text");
  51. txt.setLocation(100, 100);
  52.  
  53. GroupLayout layout = new GroupLayout(panel);
  54. panel.setLayout(layout);
  55. }
  56.  
  57. public static void main(String[] args) {
  58. // TODO code application logic here
  59. java.awt.EventQueue.invokeLater(new Runnable() {
  60. public void run() {
  61. new Example();
  62. }
  63. });
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement