他们有没有办法使您的Java GUI使用Window Builder可以在Eclipse中使用Graphics?

问题描述

我正在尝试使用2D图形并将其与Eclipse中的Window Builder一起使用,并且尝试了很多使用方式的组合,但是我一直遇到错误,它不允许我运行它,因为它会给我语法错误否则事情甚至无法正常工作。

我尝试制作一种方法并尝试制作Rectangle形状,但是没有用。我喜欢解决这个问题,但不确定如何解决问题。

代码示例为

代码将作为基础。

package com.cookie.clicker;

import java.awt.EventQueue;

import javax.swing.JFrame;

public class GraphicsTest {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokelater(new Runnable() {
            public void run() {
                try {
                    GraphicsTest window = new Graphicstest();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printstacktrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Graphicstest() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100,100,450,300);
        frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
    }

}

如果您设法在此添加一个矩形,将不胜感激!

解决方法

您的课程必须扩展JFrame。将来应使用WindowBuilder提供的向导。选择您的Java程序包,然后按CTRL + N。这将打开“新建”向导,您可以在其中选择WB JFrame类。

入门页面在这里:

https://help.eclipse.org/latest/topic/org.eclipse.wb.doc.user/html/index.html