| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 987 人关注过本帖
标题:双人围棋游戏界面的问题
只看楼主 加入收藏
oujianqiang
Rank: 1
等 级:新手上路
帖 子:138
专家分:0
注 册:2006-5-16
收藏
 问题点数:0 回复次数:1 
双人围棋游戏界面的问题

这是我设计的一个围棋游戏界面,(功能还没有实现),编译过了,但是怎么也不能运行,请各位帮一下忙,修改一下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import sun.audio.*;
import java.util.*;

public class WeiQi extends JFrame
{
public static void main(String args[])
{
WeiQi screen=new WeiQi();
}
public WeiQi()
{
qipan pan1;
jishi pan2;
pan1=new qipan();
pan2=new jishi();
Container con=getContentPane();
con.add(pan1,BorderLayout.CENTER);
con.add(pan2,BorderLayout.EAST);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
});
setSize(500,600);
setVisible(true);
}
}

class qipan extends JPanel implements MouseListener
{
Graphics write=getGraphics();
int dx=5,dy=5,x=0,y=0;
boolean flag=true;
public qipan()
{
setBackground(Color.yellow);
this.addMouseListener(this);
}
public void pain(Graphics g)
{
write.setColor(Color.black);
for(int i=0;i<19;i++)
{ write.drawLine(dx,y+dy,19*dx,y+dy);
y=y+5;
}
for(int j=0;j<19;j++)
{ write.drawLine(x+dx,dy,x+dx,19*dx);
x=x+5;
}
}
public void update(Graphics g)
{
pain(g);
}
public void mousePressed(MouseEvent e)
{ int xl,yl;
xl=e.getX();
yl=e.getY();
if(flag){write.setColor(Color.black); flag=false;}
else {write.setColor(Color.white); flag=true;}
if(xl%5==0&yl%5==0) write.fillOval(xl,yl,2,2);
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
}

class jishi extends JPanel implements ActionListener,Runnable
{
private JButton but1,but2;
private JTextField text1,text2,text3,text;
private JLabel lab1,lab2,lab3,lab4;
private int hour,minute,second;
String ho,mu,se;
Thread t;
boolean flag=true;
public jishi()
{
but1=new JButton("start");
but2=new JButton("end");
lab1=new JLabel("hours");
lab2=new JLabel("minutes");
lab3=new JLabel("seconds");
lab4=new JLabel("times count");
but1.addActionListener(this);
but2.addActionListener(this);
this.add(lab1); this.add(text1);
this.add(lab2); this.add(text2);
this.add(lab3); this.add(text3);
this.add(lab4); this.add(text);
}
public void actionPerformed(ActionEvent e)
{
Object c=e.getSource();
if(c==but1)
{ String s=but1.getLabel();
t=new Thread(this);
t.start();
if(s.equals("pause"))
{ t.suspend();
but1.setLabel("start");
}
else {t.resume(); but1.setLabel("pause");}
}
else if(c==but2)
{ t.stop();
new dialoge();
}
}
public void run()
{
ho=text1.getText();
mu=text2.getText();
se=text3.getText();
hour=Integer.parseInt(ho);
minute=Integer.parseInt(mu);
second=Integer.parseInt(se);
if(minute==0&second==0)
{ hour=hour-1;
minute=59;
second=60;
}
while(flag)
{
second--;
if(second==0&minute!=0)
{ minute--;
second=59;
}
if(minute==0&hour!=0)
{ hour--;
minute=59;
}
if(hour==0&minute==0&second==0) flag=false;
text.setText(String.valueOf(hour)+":"+String.valueOf(minute)+":"+String.valueOf(second));
try
{ Thread.sleep(1000);
}catch(InterruptedException e){return;}
}
//JOptionPane.showMessageDialog(null,"时间到");
new dialoge();
}
}

class dialoge extends JDialog implements ActionListener
{
JButton ok;
JPanel pan;
JLabel la;
AudioStream as;
public dialoge()
{
try
{ InputStream in=new FileInputStream("爱你一定很快乐.mid");
as=new AudioStream(in);
}catch(Exception e){e.printStackTrace();}
setTitle("message");
ok=new JButton("yes");
ok.addActionListener(this);
la=new JLabel("GAME OVER",JLabel.CENTER);
pan=new JPanel();
pan.setLayout(new BorderLayout());
pan.add(la,BorderLayout.CENTER);
pan.add(ok,BorderLayout.SOUTH);
getContentPane().add(pan);
setSize(250,200);
setLocation(300,250);
setVisible(true);
if(as!=null)
AudioPlayer.player.start(as);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{ AudioPlayer.player.stop(as);
setVisible(false);
}
}
}

搜索更多相关主题的帖子: 游戏界面 import 围棋 双人 java 
2006-06-05 21:56
wtyl0088
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-3-24
收藏
得分:0 
以下是引用oujianqiang在2006-6-5 21:56:00的发言:

这是我设计的一个围棋游戏界面,(功能还没有实现),编译过了,但是怎么也不能运行,请各位帮一下忙,修改一下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import sun.audio.*;
import java.util.*;

public class WeiQi extends JFrame
{
public static void main(String args[])
{
WeiQi screen=new WeiQi();
}
public WeiQi()
{
qipan pan1;
jishi pan2;
pan1=new qipan();
pan2=new jishi();
Container con=getContentPane();
con.add(pan1,BorderLayout.CENTER);
con.add(pan2,BorderLayout.EAST);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
});
setSize(500,600);
setVisible(true);
}
}

class qipan extends JPanel implements MouseListener
{
Graphics write=getGraphics();
int dx=5,dy=5,x=0,y=0;
boolean flag=true;
public qipan()
{
setBackground(Color.yellow);
this.addMouseListener(this);
}
public void pain(Graphics g)
{
write.setColor(Color.black);
for(int i=0;i<19;i++)
{ write.drawLine(dx,y+dy,19*dx,y+dy);
y=y+5;
}
for(int j=0;j<19;j++)
{ write.drawLine(x+dx,dy,x+dx,19*dx);
x=x+5;
}
}
public void update(Graphics g)
{
pain(g);
}
public void mousePressed(MouseEvent e)
{ int xl,yl;
xl=e.getX();
yl=e.getY();
if(flag){write.setColor(Color.black); flag=false;}
else {write.setColor(Color.white); flag=true;}
if(xl%5==0&yl%5==0) write.fillOval(xl,yl,2,2);
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
}

class jishi extends JPanel implements ActionListener,Runnable
{
private JButton but1,but2;
private JTextField text1,text2,text3,text;
private JLabel lab1,lab2,lab3,lab4;
private int hour,minute,second;
String ho,mu,se;
Thread t;
boolean flag=true;
public jishi()
{
but1=new JButton("start");
but2=new JButton("end");
lab1=new JLabel("hours");
lab2=new JLabel("minutes");
lab3=new JLabel("seconds");
lab4=new JLabel("times count");
but1.addActionListener(this);
but2.addActionListener(this);
this.add(lab1); this.add(text1);//这里没有初始化
this.add(lab2); this.add(text2);//还有这里
this.add(lab3); this.add(text3);//这里
this.add(lab4); this.add(text);//和这里 修改了应该就可以了
}
public void actionPerformed(ActionEvent e)
{
Object c=e.getSource();
if(c==but1)
{ String s=but1.getLabel();
t=new Thread(this);
t.start();
if(s.equals("pause"))
{ t.suspend();
but1.setLabel("start");
}
else {t.resume(); but1.setLabel("pause");}
}
else if(c==but2)
{ t.stop();
new dialoge();
}
}
public void run()
{
ho=text1.getText();
mu=text2.getText();
se=text3.getText();
hour=Integer.parseInt(ho);
minute=Integer.parseInt(mu);
second=Integer.parseInt(se);
if(minute==0&second==0)
{ hour=hour-1;
minute=59;
second=60;
}
while(flag)
{
second--;
if(second==0&minute!=0)
{ minute--;
second=59;
}
if(minute==0&hour!=0)
{ hour--;
minute=59;
}
if(hour==0&minute==0&second==0) flag=false;
text.setText(String.valueOf(hour)+":"+String.valueOf(minute)+":"+String.valueOf(second));
try
{ Thread.sleep(1000);
}catch(InterruptedException e){return;}
}
//JOptionPane.showMessageDialog(null,"时间到");
new dialoge();
}
}

class dialoge extends JDialog implements ActionListener
{
JButton ok;
JPanel pan;
JLabel la;
AudioStream as;
public dialoge()
{
try
{ InputStream in=new FileInputStream("爱你一定很快乐.mid");
as=new AudioStream(in);
}catch(Exception e){e.printStackTrace();}
setTitle("message");
ok=new JButton("yes");
ok.addActionListener(this);
la=new JLabel("GAME OVER",JLabel.CENTER);
pan=new JPanel();
pan.setLayout(new BorderLayout());
pan.add(la,BorderLayout.CENTER);
pan.add(ok,BorderLayout.SOUTH);
getContentPane().add(pan);
setSize(250,200);
setLocation(300,250);
setVisible(true);
if(as!=null)
AudioPlayer.player.start(as);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok)
{ AudioPlayer.player.stop(as);
setVisible(false);
}
}
}

[此贴子已经被作者于2006-6-5 22:53:00编辑过]


2006-06-05 22:51
快速回复:双人围棋游戏界面的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087840 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved