如何“绘画”面板?

时间:2018-12-16 19:16:35

标签: java swing

我以intellij gui形式制作了gui,但是我不知道如何编辑已经存在的组件。例如,如何使用DrawString()仅绘制panel2?

import java.awt.Graphics;
import javax.swing.*;

public class Frame2 extends JFrame {
    private JPanel mainPanel;
    private JButton edytujWynikButton;
    private JComboBox comboBox1;
    private JButton dodajWynikButton;
    private JComboBox comboBox2;
    private JButton pokazTabeleButton;
    private JPanel panel1;
    private JPanel panel2;
    private JPanel panel3;

    public Frame2() {
        add(mainPanel);
        pack();
        setSize(800, 400);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLocation(500, 300);
    }

    public class DrawString extends JPanel {

        String[] ArrayOfTeams = DBconnector.getData();
        private static final long serialVersionUID = 1L;

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            int MESSAGE_X = 50;
            int MESSAGE_Y = 15;
            for (String element : ArrayOfTeams) {
                g.drawString(element, MESSAGE_X, MESSAGE_Y);
                MESSAGE_Y = MESSAGE_Y + 30;
            }    
        }    
    }
}

0 个答案:

没有答案