fork(1) download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package SwingControl;
  7.  
  8. import java.awt.Color;
  9. import java.awt.Container;
  10. import java.awt.HeadlessException;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14.  
  15. /**
  16.  *
  17.  * @author ta
  18.  */
  19. public class BoxLayout extends JFrame {
  20.  
  21. private JPanel jpn1,jpn2;
  22.  
  23. private JButton jbt1,jbt2,jbt3,jbt4,jbt5;
  24.  
  25.  
  26. public BoxLayout(String title) throws HeadlessException {
  27.  
  28. super(title);
  29.  
  30. this.setSize(600,300);
  31. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32. this.setLocationRelativeTo(null);
  33. this.setVisible(true);
  34.  
  35.  
  36.  
  37. creatAndShow();
  38.  
  39.  
  40. }
  41.  
  42. public void creatAndShow() {
  43. // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates
  44. jpn1 = new JPanel();
  45. jbt1 = new JButton("BOX LAYOUT");
  46. jbt2 = new JButton("X_AXIS");
  47. jbt3 = new JButton("Y_AXIS");
  48. jbt4 = new JButton("Het cho chua");
  49. jbt5 = new JButton("Thi xuong dong");
  50. jpn1.setLayout(new javax.swing.BoxLayout(jpn1,javax.swing.BoxLayout.Y_AXIS));
  51.  
  52. jbt1.setForeground(Color.red);
  53. jpn1.add(jbt1);
  54.  
  55.  
  56. jbt2.setForeground(Color.blue);
  57. jpn1.add(jbt2);
  58.  
  59.  
  60. jbt3.setForeground(Color.ORANGE);
  61. jpn1.add(jbt3);
  62.  
  63. jpn2 = new JPanel();
  64. jpn2.setLayout(new java.awt.FlowLayout());
  65. jpn2.add(jbt4);
  66. jpn2.add(jbt5);
  67.  
  68. Container con = getContentPane();
  69. con.add(jpn1);
  70.  
  71. }
  72.  
  73. public static void main(String[] args) {
  74.  
  75. new BoxLayout("MY WINDOW");
  76. // box.setSize(600,300);
  77. // box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  78. // box.setLocationRelativeTo(null);
  79. // box.setVisible(true);
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91. }
  92.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:19: error: class BoxLayout is public, should be declared in a file named BoxLayout.java
public class BoxLayout extends JFrame {
       ^
1 error
stdout
Standard output is empty