我是初學者,但我一直在處理這個未知問題。請查看我已編碼的這個簡單程序,並解釋它爲什麼不能編譯我。問題是我已經從老師那裏複製了這段代碼,並且在他的機器上工作正常。然後,當我試圖在我的機器上運行這個例子時,我得到了13個錯誤!簡單程序停止編譯過程中的Java錯誤,請幫忙
這是第一類:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class radio extends JFrame{
private JTextField tf;
private Font pf;
private Font bf;
private Font itf;
private Font bif;
private JRadioButton pb;
private JRadioButton bb;
private JRadioButton ib;
private JRadioButton bib;
private ButtonGroup group;
public radio(){
super("raido buttonseses");
setLayout(new FlowLayout());
tf = new JTextField("buggedy buggedy boo", 25);
add(tf);
pb = new JRadioButton("plain", true);
bb = new JRadioButton("bold", false);
ib = new JRadioButton("italic", false);
bib = new JRadioButton("bold and italic", false);
add(pb);
add(bb);
add(ib);
add(bib);
group = new ButtonGroup();
group.add(pb);
group.add(bb);
group.add(ib);
group.add(bib);
pf = new Font("Serif", Font.PLAIN, 14);
bf = new Font("Serif", Font.BOLD, 14);
itf = new Font("Serif", Font.ITALIC, 14);
bif = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
tf.setFont(pf);
//wait for event to happen pass in font obj to constructor
pb.addItemListener(new HandlerClass(pf));
bb.addItemListener(new HandlerClass(bf));
ib.addItemListener(new HandlerClass(itf));
bib.addItemListener(new HandlerClass(bif));
}
private class HandlerClass implements ItemListener{
private Font font;
// font obj gets variable font
public HandlerClass(Font f){
font = f;
}
//sets font to font obj that was passed in
public void itemStateChanged(ItemEvent event){
tf.setFont(font);
}
}
}
當年這裏是我一直在試圖運行第二個主類:
import javax.swing.JFrame;
public class radiobutton{
public static void main(String[] args) {
radio go = new radio();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300,200);
go.setVisible(true);
}
}
我知道有人在看着這個和思考的答案是如此明顯,但對於像我這樣的初學者來說,這不是很清楚。下面是當我嘗試編譯,我又回到了我的錯誤:
javac radiobutton.java
./JFrame.java:1: JFrame is already defined in this compilation unit
import javax.swing.JFrame;
^
radiobutton.java:7: cannot find symbol
symbol : method setDefaultCloseOperation(int)
location: class radio
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
^
radiobutton.java:8: cannot find symbol
symbol : method setSize(int,int)
location: class radio
go.setSize(300,200);
^
radiobutton.java:9: cannot find symbol
symbol : method setVisible(boolean)
location: class radio
go.setVisible(true);
^
./JFrame.java:8: cannot find symbol
symbol : variable EXIT_ON_CLOSE
location: class JFrame
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
^
./radio.java:19: cannot find symbol
symbol : constructor JFrame(java.lang.String)
location: class JFrame
super("raido buttonseses");
^
./radio.java:20: cannot find symbol
symbol : method setLayout(java.awt.FlowLayout)
location: class radio
setLayout(new FlowLayout());
^
./radio.java:22: cannot find symbol
symbol : class JTExtField
location: class radio
tf = new JTExtField("buggedy buggedy boo", 25);
^
./radio.java:23: cannot find symbol
symbol : method add(javax.swing.JTextField)
location: class radio
add(tf);
^
./radio.java:30: cannot find symbol
symbol : method add(javax.swing.JRadioButton)
location: class radio
add(pb);
^
./radio.java:31: cannot find symbol
symbol : method add(javax.swing.JRadioButton)
location: class radio
add(bb);
^
./radio.java:32: cannot find symbol
symbol : method add(javax.swing.JRadioButton)
location: class radio
add(ib);
^
./radio.java:33: cannot find symbol
symbol : method add(javax.swing.JRadioButton)
location: class radio
add(bib);
^
13 errors
我的猜測是,這事做在的Java函數進口的星號。我在正確的軌道上嗎?感謝您看看這個愚蠢的問題,並非常感謝任何幫助。
它完美地編譯對我來說,嘗試運行Java的版本,告訴我們輸出 – 2010-11-04 07:06:38