Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Gui程序编译错误_Java_User Interface_Compilation - Fatal编程技术网

Java Gui程序编译错误

Java Gui程序编译错误,java,user-interface,compilation,Java,User Interface,Compilation,我正在尝试编写一段代码,它有一个gui,可以获得2个数字的GCD。当我试图编译我的代码时,我总是遇到一个错误 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 {

我正在尝试编写一段代码,它有一个gui,可以获得2个数字的GCD。当我试图编译我的代码时,我总是遇到一个错误

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中运行了您的程序,它似乎运行得很好……没有错误!下载诸如eclipse之类的IDE或任何您喜欢的东西,并尝试从那里运行程序


你用什么来编译这个程序?你试过执行一个干净的编译吗?我在使用netbeans,但遇到了这个错误,这真的很烦人lol@Saint这与你的软件包有关…你能发布你项目的目录结构图吗?我设法弄明白了,谢谢你的帮助。我最终删除了主类并开始了一个新项目,这似乎解决了问题,但不知道为什么lol@Saint没问题。如果你觉得答案在任何方面都有用,请投赞成票/+1。谢谢,保重