|
| 1 | +package view; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.awt.EventQueue; |
| 5 | + |
| 6 | +import javax.swing.JButton; |
| 7 | +import javax.swing.JFrame; |
| 8 | +import javax.swing.JInternalFrame; |
| 9 | +import javax.swing.JLabel; |
| 10 | +import javax.swing.JPanel; |
| 11 | +import javax.swing.border.EmptyBorder; |
| 12 | +import javax.swing.JSplitPane; |
| 13 | +import javax.swing.JTabbedPane; |
| 14 | +import javax.swing.JToolBar; |
| 15 | +import javax.swing.JDesktopPane; |
| 16 | + |
| 17 | +public class PanelTest extends JFrame { |
| 18 | + |
| 19 | + private JPanel contentPane; |
| 20 | + |
| 21 | + /** |
| 22 | + * Launch the application. |
| 23 | + */ |
| 24 | + public static void main(String[] args) { |
| 25 | + EventQueue.invokeLater(new Runnable() { |
| 26 | + public void run() { |
| 27 | + try { |
| 28 | + PanelTest frame = new PanelTest(); |
| 29 | + frame.setVisible(true); |
| 30 | + } catch (Exception e) { |
| 31 | + e.printStackTrace(); |
| 32 | + } |
| 33 | + } |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Create the frame. |
| 39 | + */ |
| 40 | + public PanelTest() { |
| 41 | + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 42 | + setBounds(100, 100, 823, 523); |
| 43 | + contentPane = new JPanel(); |
| 44 | + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 45 | + |
| 46 | + setContentPane(contentPane); |
| 47 | + contentPane.setLayout(null); |
| 48 | + |
| 49 | + // JSplitPane |
| 50 | + JSplitPane splitPane = new JSplitPane(); |
| 51 | + splitPane.setBounds(35, 68, 392, 59); |
| 52 | + splitPane.setDividerLocation(200); |
| 53 | + contentPane.add(splitPane); |
| 54 | + |
| 55 | + // JTabbedPane |
| 56 | + JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); |
| 57 | + tabbedPane.setBounds(35, 166, 210, 159); |
| 58 | + contentPane.add(tabbedPane); |
| 59 | + |
| 60 | + JPanel panel1 = new JPanel(); |
| 61 | + panel1.add(new JLabel("This is Tab 1")); |
| 62 | + tabbedPane.addTab("Tab 1", null, panel1, "Go to Tab 1"); |
| 63 | + |
| 64 | + JPanel panel2 = new JPanel(); |
| 65 | + panel2.add(new JButton("Click Me!")); |
| 66 | + tabbedPane.addTab("Tab 2", null, panel2, "Go to Tab 2"); |
| 67 | + |
| 68 | + JPanel panel3 = new JPanel(); |
| 69 | + panel3.setBackground(Color.PINK); |
| 70 | + tabbedPane.addTab("Tab 3", null, panel3, "Go to Tab 3"); |
| 71 | + |
| 72 | + // JToolBar |
| 73 | + JToolBar toolBar = new JToolBar(); |
| 74 | + toolBar.setBounds(485, 71, 194, 43); |
| 75 | + contentPane.add(toolBar); |
| 76 | + |
| 77 | + // Thêm nút vào thanh công cụ |
| 78 | + JButton newButton = new JButton("New"); |
| 79 | + newButton.addActionListener(e -> System.out.println("New clicked!")); |
| 80 | + toolBar.add(newButton); |
| 81 | + |
| 82 | + JButton openButton = new JButton("Open"); |
| 83 | + openButton.addActionListener(e -> System.out.println("Open clicked!")); |
| 84 | + toolBar.add(openButton); |
| 85 | + |
| 86 | + JButton saveButton = new JButton("Save"); |
| 87 | + saveButton.addActionListener(e -> System.out.println("Save clicked!")); |
| 88 | + toolBar.add(saveButton); |
| 89 | + |
| 90 | + toolBar.addSeparator(); |
| 91 | + |
| 92 | + JButton exitButton = new JButton("Exit"); |
| 93 | + exitButton.addActionListener(e -> System.exit(0)); |
| 94 | + toolBar.add(exitButton); |
| 95 | + |
| 96 | + JDesktopPane desktopPane = new JDesktopPane(); |
| 97 | + desktopPane.setBounds(334, 166, 433, 296); |
| 98 | + contentPane.add(desktopPane); |
| 99 | + |
| 100 | + JInternalFrame internalFrame = new JInternalFrame("New JInternalFrame"); |
| 101 | + internalFrame.setBounds(32, 25, 227, 165); |
| 102 | + desktopPane.add(internalFrame); |
| 103 | + |
| 104 | + JInternalFrame internalFrame_1 = new JInternalFrame("New JInternalFrame"); |
| 105 | + internalFrame_1.setBounds(269, 104, 142, 165); |
| 106 | + desktopPane.add(internalFrame_1); |
| 107 | + internalFrame_1.setVisible(true); |
| 108 | + internalFrame.setVisible(true); |
| 109 | + |
| 110 | + } |
| 111 | +} |
0 commit comments