0

嗨,我已经完成了一个简单的 GUI,但似乎无法弄清楚为什么我的 drawLines 等没有绘制到页面上。在添加滑块以调整线条相交的位置之前,我想在 DrawingPanel 上绘制相交线,但似乎无法显示它们。我对java很陌生,代码还不是很完整,但是任何帮助都将不胜感激!谢谢

面板

package JPanel;
import java.awt.*;
import javax.swing.*;

public class JPanel {

    public static void main(String[] args) {

        JFrame frame = new JFrame("GUI Design");

frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
BoxLayout layout = new BoxLayout (frame.getContentPane(), BoxLayout.X_AXIS);
frame.setLayout(layout); 

JPanel DrawingPanel = new JPanel();
JPanel ControlPanel = new JPanel();

ControlPanel.setBackground (Color.WHITE);
ControlPanel.setPreferredSize (new Dimension (200, 500));
DrawingPanel.setPreferredSize (new Dimension (500, 500));
frame.setSize(700,500);

JLabel label1 = new JLabel ("Quadrant");
JLabel label2 = new JLabel ("X: " + x + ", Y: " + y);
double x=0;
double y=0;

JSlider slide = new JSlider();
slide.setOrientation(SwingConstants.HORIZONTAL);
slide.setMinimum(1);
slide.setMaximum(4);

ControlPanel.add (label1);
ControlPanel.add (slide);
ControlPanel.add (label2);

frame.getContentPane().add(DrawingPanel);
frame.getContentPane().add(ControlPanel);
frame.pack();
frame.setVisible(true);

    }

}

绘图面板

package DrawingPanel;
import javax.swing.*;
import java.awt.*;
import java.util.*;

public class DrawingPanel extends JPanel {


    public void paint (Graphics page) {
        super.paintComponent (page);
        page.drawLine(10, 10, 180, 300);

      //I have tried messing around with this but can't get it to draw. 
      //super.paintComponent also returns a 'cannot find symbol' error 
      //which i am confused about. Also the code is imcomplete

    }
}
4

0 回答 0