import java.awt.*; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; public class Draw { public static void main(String args[]) { Border border = BorderFactory.createLineBorder(Color.BLUE, 1); //create JFrame Object as the container JFrame frame = new JFrame("Frame Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(1000, 500)); frame.setLayout(null); //create label JLabel label_1 = new JLabel("Label 1"); label_1.setBorder(border); label_1.setBounds(10, 20, 200, 100); //create button JButton button = new JButton("Button"); button.setBounds(300, 300, 200, 50); //add component frame.add(label_1, BorderLayout.EAST); frame.add(button, BorderLayout.SOUTH); //display frame.pack();//adjust frame size frame.setVisible(true); } }
import java.awt.*; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; public class Draw { public static void main(String args[]) { Border border = BorderFactory.createLineBorder(Color.BLUE, 1); //create JFrame Object as the container JFrame frame = new JFrame("Frame Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.setPreferredSize(new Dimension(700, 400)); frame.getContentPane().setBackground(new Color(255, 255, 255)); //create button JButton button = new JButton("Button East"); button.setPreferredSize(new Dimension(200, 100)); JButton button2 = new JButton("Button West"); button2.setPreferredSize(new Dimension(200, 100)); JButton button3 = new JButton("Button Center"); button3.setPreferredSize(new Dimension(200, 100)); JButton button4 = new JButton("Button North"); button4.setPreferredSize(new Dimension(200, 100)); JButton button5 = new JButton("Button South"); button5.setPreferredSize(new Dimension(200, 100)); //add component frame.add(button, BorderLayout.EAST); frame.add(button2, BorderLayout.WEST); frame.add(button3, BorderLayout.CENTER); frame.add(button4, BorderLayout.NORTH); frame.add(button5, BorderLayout.SOUTH); //display frame.pack();//adjust frame size frame.setVisible(true); } }
import java.awt.*; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; public class Draw { public static void main(String args[]) { Border border = BorderFactory.createLineBorder(Color.BLUE, 1); //create JFrame Object as the container JFrame frame = new JFrame("Frame Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout()); frame.setPreferredSize(new Dimension(700, 400)); frame.getContentPane().setBackground(new Color(255, 255, 255)); //create buttons JButton button = new JButton("Button 1"); button.setPreferredSize(new Dimension(200, 100)); JButton button2 = new JButton("Button 2"); button2.setPreferredSize(new Dimension(200, 100)); JButton button3 = new JButton("Button 3"); button3.setPreferredSize(new Dimension(200, 100)); JButton button4 = new JButton("Button 4"); button4.setPreferredSize(new Dimension(200, 100)); JButton button5 = new JButton("Button 5"); button5.setPreferredSize(new Dimension(200, 100)); //add component frame.add(button); frame.add(button2); frame.add(button3); frame.add(button4); frame.add(button5); //display frame.pack();//adjust frame size frame.setVisible(true); } }