Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 这个问题怎么解决!!!!!!!!!!!!!!大家帮帮忙啊 我是初学者
zzw5516





发贴: 10
积分: 0
于 2005-06-15 15:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:0
程序:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class Onee extends Frame{
//定义成员变量
int m;//获取文本数字的变量
boolean mp;
boolean mr;
private int count=0;
public boolean a[][]=new boolean[m][m];
public boolean b[][]=new boolean[m][m];
public boolean c[][]=new boolean[m][m];
int i1=0;
int j1=0;
//界面画线变量
private int x=55;
private int y=50;
private int n=50;
int i=0;
int j=0;
Dialog dlg=new Dialog(this,"111",true);
FlowLayout fw=new FlowLayout();
Vector vLines=new Vector();
TextField tf=new TextField(15);
Panel p=new Panel();
//组件重绘
public void paint(Graphics g)
{
g.setColor(Color.red);
Enumeration e=vLines.elements();
while(e.hasMoreElements())
{
MyLine ln=(MyLine)e.nextElement();
ln.drawMe(g);
}
}
//框架及其组件事件处理
public Onee(){
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
MenuItem menuFileEasy = new MenuItem();
MenuItem menuFileHard = new MenuItem();
Menu menuOrder =new Menu();
MenuItem menuOrderCp=new MenuItem();
MenuItem menuOrderMe=new MenuItem();
Menu menuVersion= new Menu();
MenuItem menuVersionGy=new MenuItem();

menuFile.setLabel("选项");
menuFileEasy.setLabel("容易");
menuFileHard.setLabel("困难");
menuFileExit.setLabel("退出");
menuOrder.setLabel("顺序");
menuOrderCp.setLabel("电脑先下");
menuOrderMe.setLabel("我先下");
menuVersion.setLabel("版本");
menuVersionGy.setLabel("关于");

menuFile.add(menuFileEasy);
menuFile.add(menuFileHard);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuOrder.add(menuOrderCp);
menuOrder.add(menuOrderMe);
menuBar.add(menuOrder);
menuVersion.add(menuVersionGy);
menuBar.add(menuVersion);


//主界面控件
Button b1=new Button("开始");
p.setLayout(new FlowLayout());
p.add(new Label("请输入棋格数后回车:"));
p.add(tf);
p.add(b1);
this.add("South",p);
//界面
setTitle("一字棋");
setMenuBar(menuBar);
setSize(new Dimension(800, 600));
//小按钮
Button bb=new Button("确定");
dlg.setLayout(fw);
dlg.add(bb);
setVisible(true);
//容易
menuFileEasy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mp=true;
System.out.println("mp="+mp);
}
});
//困难
menuFileHard.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mp=false;
System.out.println("mp="+mp);
}
});
//退出
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Onee.this.windowClosed();
}
});
//电脑先下
menuOrderCp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mr=true;
System.out.println("mr="+mr);
}
});
//我先下
menuOrderMe.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mr=false;
System.out.println("mr="+mr);
}
});
//关于
menuVersionGy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dlg.setModal(true);
dlg.setBounds(400,200,200,150);
//dlg.list("22222222222");
dlg.setVisible(true);
}
});
//确定
bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dlg.dispose();
}
});
//窗口叉叉
this.addWindowListener
(
new WindowAdapter(){
public void windowClosing(WindowEvent e) {
Onee.this.windowClosed();
}
});
//文本事件处理
tf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
m=Integer.parseInt(tf.getText());
//System.out.println("m="+m);
if(m<2) {
dlg.setModal(true);
dlg.setBounds(400,200,200,150);
//dlg.list("22222222222");
dlg.setVisible(true);
}
((TextField)e.getSource()).setText("");
}
});
//开始 按钮事件处理
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Graphics g=Onee.this.getGraphics();
g.setColor(Color.red);
while(i<m+1){
g.drawLine(x+i*n,y,x+i*n,y+m*n);
vLines.add(new MyLine(x+i*n,y,x+i*n,y+m*n));
g.drawLine(x,y+i*n,x+m*n,y+i*n);
vLines.add(new MyLine(x,y+i*n,x+m*n,y+i*n));
i++;
}}
});
}
//主体函数
public void zhuti(){
System.out.println("zhuti111111");
this.addMouseListener(new MouseAdapter(){
int orgX;
int orgY;
public void mousePressed(MouseEvent e)
{
orgX=e.getX();
orgY=e.getY();
System.out.println("12345");
}
public void mouseReleased(MouseEvent e){
Graphics g=Onee.this.getGraphics();
if(mp==true)//Easy 难度判断
{
while(count<m*m)
{if(mr==true)
{int i1=(int)(Math.random()*(m));
int j1=(int)(Math.random()*(m));

System.out.println("i1="+i1);
System.out.println("j1="+j1);
if(a[i1][j1]==true) //这个地方为什么就不能判断呢
System.out.println("ggggg");
g.fillRect(x+n*i1,y+n*j1,50,50);
a[i1][j1]=true;//还有这里这个地方为什么就也不能赋值呢********// b[i1][j1]=true;;//还有这里这个地方为什么就也不能赋值呢
mr=false;
count=count+1;
}
}
}
}
});
}
protected void windowClosed(){System.exit(0);}
//主函数***********************************************
public static void main(String[] args) {
Onee ee=new Onee();
ee.zhuti();
}
}
class MyLine
{
private int x1;
private int y1;
private int x2;
private int y2;
public MyLine(int x1,int y1,int x2,int y2)
{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
}
public void drawMe(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
}

应该不是基本的数组越界问题吧!!!!????


kavinwang edited on 2005-06-15 15:42


话题树型展开
人气 标题 作者 字数 发贴时间
4057 这个问题怎么解决!!!!!!!!!!!!!!大家帮帮忙啊 我是初学者 zzw5516 7117 2005-06-15 15:14
3111 Re:这个问题怎么解决!!!!!!!!!!!!!!大家帮帮忙啊 我是初学者 zzw5516 55 2005-06-15 15:17
2914 Re:这个问题怎么解决!!!!!!!!!!!!!!大家帮帮忙啊 我是初学者 kavinwang 200 2005-06-15 15:44
3330 Re:这个问题怎么解决!!!!!!!!!!!!!!大家帮帮忙啊 我是初学者 zzw5516 36 2005-06-15 19:54

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923