Gui程序编译错误

时间:2013-12-08 21:34:04

标签: 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 {
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;
}

}

1 个答案:

答案 0 :(得分:1)

我在Eclipse中运行你的程序,它似乎运行正常....没有错误!下载eclipse或任何您喜欢的IDE,并尝试从那里运行程序。

enter image description here