我如何做到这一点?

时间:2020-06-05 02:23:15

标签: user-interface input jframe drawing

> public class DISTANCE extends JFrame {
    String input;
    String output;
    JLabel output5;
    String L1X1, L1X2, L1Y1, L1Y2;
    String L2X1, L2X2, L2Y1, L2Y2;
    String LINE;
    public static void main(String[] args) {

        DISTANCE frame = new DISTANCE();
        frame.setSize(600, 600);
        frame.setTitle("DRAW-A-LINA");
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
int counter = 0;
    public void paint(Graphics g) {
        do {
            L1X1 = JOptionPane.showInputDialog("Enter the X1 coordinate for Line 1 here:");
            counter++;
            L1X2 = JOptionPane.showInputDialog("Then, the X2 coordinate for Line 1 here:");
            counter++;
            L1Y1 = JOptionPane.showInputDialog("And the Y1 coordinate for Line 1 here:");
            counter++;
            L1Y2 = JOptionPane.showInputDialog("Plus the Y2 coordinate for Line 1 here:");
            counter++;
            L2X1 = JOptionPane.showInputDialog("Now, enter the X1 coordinate for Line 2 here:");
            counter++;
            L2X2 = JOptionPane.showInputDialog("And the X2 coordinate for Line 2 here:");
            counter++;
            L2Y1 = JOptionPane.showInputDialog("And the Y1 coordinate for Line 2 here:");
            counter++;
            L2Y2 = JOptionPane.showInputDialog("And lastly, the Y2 coordinate for Line 2 here:");
            counter++;
        }
        while(counter < 8);
        //CONVERSION TAKES PLACE AFTER INPUT
        int Line1_X1 = Integer. parseInt(L1X1);
        int Line1_X2 = Integer. parseInt(L1X2);
        int Line1_Y1 = Integer. parseInt(L1Y1);
        int Line1_Y2 = Integer. parseInt(L1Y2);
        //for line 2
        int Line2_X1 = Integer. parseInt(L2X1);
        int Line2_X2 = Integer. parseInt(L2X2);
        int Line2_Y1 = Integer. parseInt(L2Y1);
        int Line2_Y2 = Integer. parseInt(L2Y2);
        JOptionPane.showMessageDialog(null,"Ok, here's your line:");

        Graphics2D g2d =(Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        super.paint(g);
        Graphics2D g2 = (Graphics2D) g;
        g2d.drawLine(Line1_X1, Line1_Y1, Line1_X2, Line1_Y2);
        g2d.drawLine(Line2_X1, Line2_Y2, Line2_X1, Line2_Y2);
    }
}

嗨,伙计们。因此,这是针对班级作业的,因此,我立即让您知道,我不是在寻求答案。只是想弄清楚我在做什么错。 我正在创建一个面板,它将接受由x和y坐标组成的8个输入,并使用它绘制两条线。我已经在下面发布了我的代码。 1.我可以弹出JOptions输入框并提供我编写的文本提示。但是,应该在给出8个值提示后停止并绘制两条线。但是相反,它在8个输入之后绘制线,但再次从提示1开始。我希望在输入所有8个输入后消失输入选项框。 2.我画了一个jFrame,它是我打算用来绘制线条的地方,但是我的问题是我无法知道输入的线条是否适合框架。有时它只画一条线,因为第二条线的尺寸会有所不同,并且可能无法放入框中

基本上,我试图弄清楚如何制作一个GUI(我猜它与JFrame不同)以及如何将其绘制在线条上。

0 个答案:

没有答案