java - Gui程序编译错误

标签 java user-interface compilation

我正在尝试编写一些代码,该代码具有一个可以获取 2 个数字的 GCD 的 gui。当我尝试编译代码时,我不断收到错误

Error: Could not find or load main class Gooie.Gooie
Java Result: 1\

有人可以告诉我我到底做错了什么吗?

我的代码

package Gooie;

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

public class Gooie {
public static void main(String[] args) {
JFrame frame = new GcdFrame();
frame.setVisible(true);
}

}
class GcdFrame extends JFrame {
public GcdFrame() {
setTitle("Greatest Common Divisor Finder");
centerWindow(this);
setSize(267, 200);
//setResizable(false);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new GcdPanel();
this.add(panel);
}

private void centerWindow(Window w) {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
setLocation((d.width - w.getWidth()) / 2,
        (d.height - w.getHeight()) / 2);
}
}

class GcdPanel extends JPanel implements ActionListener {
private JTextField xTextField, yTextField,
    gcdTextField;
private JLabel xLabel, yLabel, gcdLabel;
private JButton calculateButton, exitButton;

public GcdPanel() {
// display panel
JPanel displayPanel = new JPanel();
// displayPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
displayPanel.setLayout(new GridLayout(4, 2));
// payment label
xLabel = new JLabel("X:");
displayPanel.add(xLabel);

// payment text field
xTextField = new JTextField(10);
displayPanel.add(xTextField);

// rate label
yLabel = new JLabel("Y:");
displayPanel.add(yLabel);

// rate text field
yTextField = new JTextField(10);
displayPanel.add(yTextField);


// future value label
gcdLabel = new JLabel("GCD:");
displayPanel.add(gcdLabel);

// future value text field
gcdTextField = new JTextField(10);
gcdTextField.setEditable(false);
gcdTextField.setFocusable(false);
displayPanel.add(gcdTextField);

// button panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

// calculate button
calculateButton = new JButton("Calculate");
calculateButton.addActionListener(this);
buttonPanel.add(calculateButton);

// exit button
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
buttonPanel.add(exitButton);

// add panels to main panel
this.setLayout(new BorderLayout());
this.add(displayPanel, BorderLayout.CENTER);
this.add(buttonPanel, BorderLayout.SOUTH);
}

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == exitButton)
    System.exit(0);
else if (source == calculateButton) {
    int x =  Integer.parseInt(xTextField.getText());
    int y = Integer.parseInt(yTextField.getText());
    int gcd = greatestCommonDivisor(x, y);
    gcdTextField.getText();
}

}
private int greatestCommonDivisor(int x, int y) {
// TODO Auto-generated method stub

while (x != y) {
    if (x > y) {
        x = x - y;
    } else {
        y = y - x;
    }
}
return y;
}

}

最佳答案

我在 Eclipse 中运行了你的程序,它似乎运行良好......没有错误!下载 IDE(例如 eclipse 或任何您喜欢的东西)并尝试从那里运行该程序。

enter image description here

关于java - Gui程序编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20459403/

相关文章:

c++ - 使用 CMake 为 visual studio 项目配置 txx 文件

java - 如何根据对象的实例进行重载?

android - 实现特殊 UI 元素列表的最佳方式?

ios - 将模型文件添加到 View Controller ,帮助 UI 正常工作

user-interface - 使用 tivo/tview GoLang 库时获取实际的表单值

compilation - 在 IntelliJ 中编译完整的 TypeScript 项目

gcc - 为什么常见的 C 编译器在输出中包含源文件名?

java - 如何以编程方式旋转背景?

java - 如何以编程方式了解机器是否在全局/专用网络中

java - 当长度可被 16 整除时,CipherInputStream 跳过最后一个字节