In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces Java how to achieve Gobang stand-alone version of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Java how to achieve Gobang stand-alone version of the article will have a harvest, let's take a look.
Java Gobang design process:
1. Create a window and design a chessboard interface
two。 Achieve mouse click, chess pieces appear, black and white chess in turn
3. Be able to judge whether to win or lose
4. Add button function
Implementation result diagram:
Import java.awt.BorderLayout;import java.awt.Color;import java.awt.Cursor;import java.awt.FlowLayout;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.JButton Import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel; public class Test {public static void main (String [] args) {new MyFrame ();}} class MyFrame extends JFrame implements MouseListener {/ / Save coordinates int x; int y; int x1; int y1 / / number of sunspots / / number of white spots / / 1 is black, 2 is white / / default starts with black flag int flag=1; / / indicates whether the game is over / / true game starts, false game ends, no more boolean canPlay=true / / Save the coordinates of previously played pieces / /'0' for no pieces,'1' for black,'2' for white int [] [] allChess=new int [19] [19]; / / int [] [] allChess=new int [25] [25]; / / the total number of current pieces int chessSum=0; BufferedImage bgImage = null; JButton withdraw=new JButton ("repentance"); JButton restart=new JButton ("start over") JButton exit=new JButton ("quit"); JPanel south=new JPanel (); public MyFrame () {this.setTitle (Gobang); setSize (630700); setLayout (new BorderLayout ()); setLocationRelativeTo (null); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); try {bgImage=ImageIO.read ("C:\ Users\\ us\\ Desktop\ 1.jpg")) } catch (IOException E1) {e1.printStackTrace ();} addMouseListener (this); / / add the form to the listening south.setLayout (new FlowLayout (FlowLayout.LEFT,60,30)); south.add (restart); south.add (withdraw); south.add (exit) / / initialize button event listener inner class MybuttonListener buttonListener = new MybuttonListener (); / / register three button events restart.addActionListener (buttonListener); withdraw.addActionListener (buttonListener); exit.addActionListener (buttonListener); / / add button panels to the southern this.add of the form (south,BorderLayout.SOUTH); setVisible (true) } public void paint (Graphics g) {int tempSum=chessSum; / / chessboard g.drawImage (bgImage,8,30,this); for (int colum=58;colum)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 268
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.