java snippet_Snippet.java

package chess;

import java.awt.Checkbox;

import java.awt.CheckboxGroup;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

class FivChese extends JFrame{//继承自窗口类

CheseGame CG;

FivChese ()

{

this.CG= new CheseGame();

addMouseListener(CG);//鼠标监听器

add(CG);

}

public static void main(String[] args) {

FivChese fivechese= new FivChese ();

fivechese.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设成退出程序,相当于是System.exit(0)

fivechese.setSize(900, 700);//设置组件的长宽大小

fivechese.setTitle("五子棋");//设置组建的自定义标题

fivechese.setVisible(true);//显示按钮

// fivechese.setResizable(true);//参数为boolean类型,resizeable值为true时,表示在生成的窗体可以自由改变大小;

}

}

class CheseGame extends JPanel implements MouseListener,ItemListener//图形用户界面工具包swing中的面板容器类,可以加入JFrame窗口中

{

int [][]map = new int[20][20];

Color []color = {Color.BLACK,Color.WHITE,Color.LIGHT_GRAY};//背景颜色

//棋子坐标

int x = -1;

int y = -1;

//判定是白棋还是黑棋

int flag = 1;

//判定胜负

int winner = 3;

JButton btn1 = new JButton("开始"); //游戏开始

JButton btn2 = new JButton("再来一局");//游戏重置

JButton btn3 = new JButton("悔棋");

//确定白棋先还是黑棋先

CheckboxGroup cbg = new CheckboxGroup();

Checkbox chb1 = new Checkbox("黑旗先开始",cbg,true);

Checkbox chb2 = new Checkbox("白旗先开始",cbg,false);

class GameStart implements ActionListener//游戏开始继承自动作监听器

{

public void actionPerformed(ActionEvent ae)//编写一个方法处理ActionEvent事件

{

if(ae.getSource() == btn1)//str.equals("Start")

{

start();

repaint();//重新描绘component的方法

btn1.setEnabled(false);//设置控件是否可用

btn2.setEnabled(true);

btn3.setEnabled(true);

chb1.setEnabled(false);

chb2.setEnabled(false);

}

if(ae.getSource() == btn2)//处理再来一局事件

{

start();

repaint();

chb1.setEnabled(true);

chb2.setEnabled(true);

}

if(ae.getSource() == btn3)//处理悔棋事件

{

repaint();

chb1.setEnabled(false);

chb2.setEnabled(false);

}

}

private void start() {

// TODO Auto-generated method stub

}

}

CheseGame()

{

this.setLayout(null);//

chb1.setBounds(650, 50, 100, 30);//设置开始控件的位置

chb2.setBounds(650, 100, 100, 30);

chb1.addItemListener(this);

chb2.addItemListener(this);

btn1.setBounds(650,150,100,30);

btn1.addActionListener(new GameStart()); //建立一个新的游戏开始对象

btn2.setBounds(650, 200, 100, 30);

btn2.addActionListener(new GameStart());

btn2.setEnabled(false);

btn3.setBounds(650, 250, 100, 30);

btn3.addActionListener(new GameStart());

this.add(btn1);

this.add(btn2);

this.add(btn3);

this.add(chb1);

this.add(chb2);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);//是父类JPanel里面的方法,会把整个面板用背景颜色重画一遍,起到清屏作用

setBackground(color[2]);//设置棋盘背景颜色

//画棋盘

for(int i = 1;i <= 20;i++)

{

g.setColor(color[0]);

g.drawLine(30, i*30 ,600 , i*30);//画线绘制棋盘格子,这是画横线的,30毫米画一条直线,从30到600

g.drawLine(i*30,30, i*30, 600);//画棋盘竖线

}

//画棋子

for(int i = 0;i < 20;i++)

for(int j = 0;j < 20;j++)

{

if(map[i][j] == 1)

{

g.setColor(color[0]);//画棋子颜色

g.fillOval((i+1)*30-15, (j+1)*30-15, 30, 30);

}

if(map[i][j] == 2)

{

g.setColor(color[1]);

g.fillOval((i+1)*30-15, (j+1)*30-15, 30, 30);//描绘棋子

}

}

}

@Override

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseEntered(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseReleased(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void itemStateChanged(ItemEvent arg0) {

// TODO Auto-generated method stub

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I don't have access to your local machine or the specific context of your question. However, I can provide you with general information about the Java OpenMap PbfWriter. The Java OpenMap PbfWriter is a library that provides a way to convert OpenStreetMap data from XML or PBF format to a binary format that can be used for faster processing and storage. The PbfWriter class is used to write data to a PBF file in version 0.6 format. To use the PbfWriter class, you would typically create an instance of the class and provide it with the output file name and other options such as compression and tile size. You would then use the various write methods of the PbfWriter to write the OpenStreetMap data to the PBF file. Here is an example code snippet that demonstrates how to use the PbfWriter class: ``` import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.openstreetmap.osmosis.core.Osmosis; import org.openstreetmap.osmosis.core.domain.v0_6.Bound; import org.openstreetmap.osmosis.core.domain.v0_6.EntityContainer; import org.openstreetmap.osmosis.core.domain.v0_6.Node; import org.openstreetmap.osmosis.core.domain.v0_6.Way; import org.openstreetmap.osmosis.core.task.v0_6.Sink; import org.openstreetmap.osmosis.pbf2.v0_6.PbfWriter; public class Example { public static void main(String[] args) throws IOException { File outputFile = new File("output.pbf"); PbfWriter writer = new PbfWriter(new FileOutputStream(outputFile)); writer.setNodes(true); writer.setWays(true); writer.setDense(true); Sink sink = writer; sink.initialize(); sink.process(new Bound(0, 0, 0, 0, null)); // Process OpenStreetMap data Osmosis.run(args); sink.complete(); sink.release(); } } ``` This code creates a PbfWriter instance and sets the options to include nodes, ways, and dense format. It then creates a Sink instance from the PbfWriter and processes a Bound entity to initialize the sink. The code then uses Osmosis to process the OpenStreetMap data and pass it to the sink for writing to the PBF file. Finally, the sink is completed and released. Note that this is just an example and you would need to modify it to suit your specific use case. Additionally, you would need to include the appropriate dependencies for the OpenMap and Osmosis libraries.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值