2010-11-05 68 views
0

我是新來的java,我有兩個類(類calc和按鈕),我需要拆分成單獨的文件和類calc使用類按鈕。他們都編譯,但是當我運行類A失敗。我怎樣才能做到這一點?java拆分源文件

這是類鈣代碼

package start; 
import javax.swing.*; 
import java.awt.event.*; 
import java.awt.Container; 
import java.awt.Insets; 
import java.awt.Dimension; 
import button.*; 

public class calc { 
private button calc_buttons; 

private static void creategui(){ 
    JFrame window = new JFrame("hello dynamic window"); 

    buttons.createbuttons(); 
    buttons.setOpaque(false); 
    window.setContentPane(buttons); 
    window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
    window.pack(); 
    window.setVisible(true); 

} 

static public void main(String[] args){ 
    creategui(); 
} 

} 

這是類按鈕

package button; 

import javax.swing.*; 
import java.awt.event.*; 
import java.awt.Container; 
import java.awt.Insets; 
import java.awt.Dimension; 

public class button /*extends JPanel implements ActionListener*/{ 

protected static JButton button1, button2, button3, button4, button5, button6, button7; 
protected static JButton button8, button9, button_fact, button_exp, button_sqrt, button_abs; 
protected static JButton button_sin, button_cos, button_tan, button_percent, button_rcl; 
protected static JButton button_MC, button_e, button_pi, button_Mplus, button_Mminus; 
protected static JButton button_C, button_AC, button_MS, button_sign; 
protected static JButton button_plus, button_minus, button_div, button_mult, button_equal; 

static public void calc_button(){ 


} 

} 

代碼我編譯時沒有錯誤消息,但是當我運行計算類我得到這個

Exception in thread "main" java.lang.NoClassDefFoundError: calc (wrong name: start/calc) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

回答

2

向上移動一個目錄(進入包含「開始」和「按鈕」的目錄)並執行此操作:

java start.calc 

順便說一句,這是一個讓大家的名字以大寫字母開頭的約定。

+0

謝謝!這是我的第一次使用Java的經驗 – romejoe 2010-11-06 00:10:47