刑警世家by蝶之灵小说:求助各位前辈关于JAVA的代码~~~~~~~~~~~~~~~~~

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/19 22:49:27
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MiniDrawPad extends JFrame //主类 {
private JButton choices[];
private String names[]={
"New",
"Open",
"Save",
"Pencil",
"Line",
"Rect",
"fRect",
"Oval",
"fOval",
"Circle",
"fCircle",
"RoundRect",
"frRect",
"Rubber",
"Color",
"Stroke",
"Word" };

private Icon items[];

JToolBar buttonPanel ; //定义按钮面板
private JLabel statusBar; //显示鼠标状态的提示条

private DrawPanel drawingArea; //画图区域
private int width=800,height=550; //定义画图区域初始大小

JCheckBox bold,italic; //定义字体风格选择框
JComboBox styles;

public MiniDrawPad() //构造函数
{
super("Drawing Pad");
JMenuBar bar=new JMenuBar(); //定义菜单条
JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');

//新建文件菜单条
JMenuItem newItem=new JMenuItem("New");
fileMenu.add(newItem);

//保存文件菜单项
JMenuItem saveItem=new JMenuItem("Save");
fileMenu.add(saveItem);

//打开文件菜单项
JMenuItem loadItem=new JMenuItem("Load");
fileMenu.add(loadItem);

fileMenu.addSeparator();

//退出菜单项
JMenuItem exitItem=new JMenuItem("Exit");
fileMenu.add(exitItem);
bar.add(fileMenu);

//设置颜色菜单条
JMenu colorMenu=new JMenu("Color");

//选择颜色菜单项
JMenuItem colorItem=new JMenuItem("Choose Color");
colorMenu.add(colorItem);
bar.add(colorMenu);

JMenu strokeMenu=new JMenu("Stroke");

JMenuItem strokeItem=new JMenuItem("Set Stroke");
strokeMenu.add(strokeItem);
bar.add(strokeMenu);

items=new ImageIcon[names.length];

//创建各种基本图形的按钮
drawingArea=new DrawPanel();
choices=new JButton[names.length];
buttonPanel = new JToolBar( JToolBar.VERTICAL ) ;
buttonPanel = new JToolBar( JToolBar.HORIZONTAL) ;
ButtonHandler handler=new ButtonHandler();
ButtonHandler1 handler1=new ButtonHandler1();

//导入需要的图形图标,这些图标都存放在与源文件相同的目录下面
for(int i=0;i<choices.length;i++)
{items[i]=new ImageIcon(names[i] + ".gif");
choices[i]=new JButton("",items[i]);
choices[i].setToolTipText(tipText[i]);
buttonPanel.add(choices[i]);
}

public static void main(String[] arguments){
JFrame newPad=new MiniDrawPad();
ExitWindow exit=new ExitWindow();
frame.addWindowListener(exit);
}
}

class ExitWindow extends WindowAdaper{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}

这段代码我想实现一个图形化界面,为什么编译有错?小妹我是初学,所以麻烦各位前辈了.谢谢
与第五行的注释错误无关,这个改过来仍然不对
public class MiniDrawPad extends JFrame //主类 {

至少你现在这个代码“{”比“}”多一个。还有你好像引用了一些不存在的类阿!

class ExitWindow extends WindowAdaper
应该是class ExitWindow extends WindowAdapter

改了一些你的代码
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MiniDrawPad extends JFrame {
private JButton choices[];
private String names[]={
"New",
"Open",
"Save",
"Pencil",
"Line",
"Rect",
"fRect",
"Oval",
"fOval",
"Circle",
"fCircle",
"RoundRect",
"frRect",
"Rubber",
"Color",
"Stroke",
"Word" };

private Icon items[];

JToolBar buttonPanel ; //定义按钮面板
private JLabel statusBar; //显示鼠标状态的提示条

private DrawPanel drawingArea; //画图区域
private int width=800,height=550; //定义画图区域初始大小

JCheckBox bold,italic; //定义字体风格选择框
JComboBox styles;

public MiniDrawPad() //构造函数
{
super("Drawing Pad");
JMenuBar bar=new JMenuBar(); //定义菜单条
JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');

//新建文件菜单条
JMenuItem newItem=new JMenuItem("New");
fileMenu.add(newItem);

//保存文件菜单项
JMenuItem saveItem=new JMenuItem("Save");
fileMenu.add(saveItem);

//打开文件菜单项
JMenuItem loadItem=new JMenuItem("Load");
fileMenu.add(loadItem);

fileMenu.addSeparator();

//退出菜单项
JMenuItem exitItem=new JMenuItem("Exit");
fileMenu.add(exitItem);
bar.add(fileMenu);

//设置颜色菜单条
JMenu colorMenu=new JMenu("Color");

//选择颜色菜单项
JMenuItem colorItem=new JMenuItem("Choose Color");
colorMenu.add(colorItem);
bar.add(colorMenu);

JMenu strokeMenu=new JMenu("Stroke");

JMenuItem strokeItem=new JMenuItem("Set Stroke");
strokeMenu.add(strokeItem);
bar.add(strokeMenu);

items=new ImageIcon[names.length];

//创建各种基本图形的按钮
drawingArea=new DrawPanel();
choices=new JButton[names.length];
buttonPanel = new JToolBar( JToolBar.VERTICAL ) ;
buttonPanel = new JToolBar( JToolBar.HORIZONTAL) ;
//ButtonHandler handler=new ButtonHandler();
//ButtonHandler1 handler1=new ButtonHandler1();

//导入需要的图形图标,这些图标都存放在与源文件相同的目录下面
for(int i=0;i<choices.length;i++)
{items[i]=new ImageIcon(names[i] + ".gif");
choices[i]=new JButton("",items[i]);
String[] tipText = new String[choices.length];
choices[i].setToolTipText(tipText[i]);
buttonPanel.add(choices[i]);
}
JFrame newPad=new MiniDrawPad();
ExitWindow exit=new ExitWindow();
JFrame frame = new JFrame();
frame.addWindowListener(exit);

}
public static void main(String[] arguments){

}
}

class ExitWindow extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}

你那个DrawPanel的类不知道是不是自己定义的,系统里面是没有。现在剩的两个错误就出在这个类上了。还有那个tipText[]也没有定义我也不知道你想写什么就定义了一个空的。frame也没有定义。还有那几个监听都不对,至少不应该定义在main()里面。望能注意一下编码规范,看起来很费事的。