|
请问ecplise环境只能编写swt的图形程序马?awt是否可用。
我在ecplise环境下编写awt有关的程序,但总是不能成功运行。希望大侠们帮帮忙。
每次运行都会出现一下报错提示:
Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Window.getToolkit() (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Frame.addNotify() (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Window.show() (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Component.show(boolean) (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Component.setVisible(boolean) (/usr/lib64/libgcj.so.6.0.0)
at Gui_1.go() (Unknown Source)
at Gui_1.main(java.lang.String[]) (Unknown Source)
at .main (/usr/lib64/libgij.so.6.0.0)
at .__libc_start_main (/lib64/libc-2.3.5.so)
Caused by: java.lang.ClassNotFoundException: gnu.java.awt.peer.gtk.GtkToolkit not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/sway/workspace/GUI_test/,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
...9 more
我的程序代码如下
//文件名 Gui_1.java
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
public class Gui_1 implements ActionListener
{
double a,b,c;
//define the component-----------------
Frame f=new Frame("基本运算操作");
//创建一个框架
FlowLayout fl=new FlowLayout(FlowLayout.CENTER,18,38);
//创建一个布局管理器
Label label1= new Label(" 操作数一");
TextField text1= new TextField(15);
Label label2= new Label(" 操作数二");
TextField text2= new TextField(15);
Label label3= new Label(" 计算结果");
TextField text3= new TextField(15);
Button button1= new Button(" 加 ");
Button button2= new Button(" 减 ");
Button button3= new Button(" 乘 ");
Button button4= new Button(" 除 ");
public void go()
//用于显示界面-------------------
{
f.setLayout(fl);
f.add(label1);f.add(text1);
f.add(label2);f.add(text2);
f.add(label3);f.add(text3);
f.add(button1);button1.addActionListener(this);
f.add(button2);button2.addActionListener(this);
f.add(button3);button3.addActionListener(this);
f.add(button4);button4.addActionListener(this);
f.setSize(300,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String k;
a=Double.parseDouble(text1.getText());
b=Double.parseDouble(text2.getText());
if(e.getSource()==button1) c=a+b;
if(e.getSource()==button2) c=a-b;
if(e.getSource()==button3) c=a*b;
if(e.getSource()==button4) c=a/b;
k=String.valueOf(c);//将C的值转成字符串形
text3.setText(k);
}
//define the main method-------------------
public static void main(String[] args)
{
Gui_1 gl= new Gui_1();
gl.go();
}
} |
|