JTabbedPane и все все - Java
Формулировка задачи:
Доброго времени суток, помогите пожалуйста разобраться с вкладками
Листинг программы
- package Working;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Toolkit;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTabbedPane;
- public class Meny
- {
- public JFrame window = new JFrame("As in the war");
- public JTabbedPane jtp = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
- public Meny()
- {
- start();
- }
- public void start()
- {
- startJFrame();
- startPane();
- }
- public void startJFrame()
- {
- window.setSize(winW, winH);
- window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- window.getContentPane().setBackground(Color.white);
- window.setLayout(null);
- window.setResizable(false);
- window.setLocationRelativeTo(null);
- window.setVisible(true);
- }
- public void startPane()
- {
- JLabel fonTab0 = new JLabel();
- jtp.addTab("Вкладка0", fonTab0);
- jtp.addTab("Вкладка1", fonTab0);
- jtp.addTab("Вкладка2", fonTab0);
- window.add(jtp);
- window.repaint();
- }
- public static void main(String[] args)
- {
- new Meny();
- }
- }
Решение задачи: «JTabbedPane и все все»
textual
Листинг программы
- public class Meny {
- public JFrame window = new JFrame("As in the war");
- public JTabbedPane jtp = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
- private int winW = 500;
- private int winH = 400;
- public Meny() {
- start();
- }
- public void start() {
- startPane();
- startJFrame();
- }
- public void startJFrame() {
- window.setSize(winW, winH);
- window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- window.getContentPane().setBackground(Color.white);
- // window.setResizable(false);
- // window.setLocationRelativeTo(null);
- window.setVisible(true);
- }
- public void startPane() {
- JPanel jPanel0 = new JPanel(new FlowLayout());
- JPanel jPanel1 = new JPanel(new FlowLayout());
- JPanel jPanel2 = new JPanel(new FlowLayout());
- JLabel fonTab0 = new JLabel("Label 0");
- JLabel fonTab1 = new JLabel("Label 1");
- JLabel fonTab2 = new JLabel("Label 2");
- jPanel0.add(fonTab0);
- jPanel0.add(fonTab1);
- jPanel1.add(new JCheckBox("CBox 0"));
- jPanel1.add(new JCheckBox("CBox 1"));
- jPanel2.add(new JButton("Button 0"));
- jPanel2.add(new JButton("Button 1"));
- JButton jButton = (JButton) jPanel2.getComponent(1);
- jButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.add(new JButton("New Button"));
- window.validate();
- }
- });
- JButton jButton2 = (JButton) jPanel2.getComponent(0);
- jButton2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.remove(jPanel2.getComponents().length-1);
- window.validate();
- window.repaint();
- }
- });
- window.setLayout(new BorderLayout());
- jtp.add("Вкладка0", jPanel0);
- jtp.add("Вкладка1", jPanel1);
- jtp.add("Вкладка2", jPanel2);
- window.add(jtp);
- window.repaint();
- }
- public static void main(String[] args) {
- new Meny();
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д