MyJFrame.java package chi1.JFrame; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Toolkit; 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.JFrame; import javax.swing.JOptionPane; public class MyJFrame extends JFrame implements MouseListener { private static final long serialVersionUID = -46847020668994298L; BufferedImage buff = null; // 声明对象,为获取图片 int x , y ; // 保存所有的点多的坐标 int[][] allChess = new int[15][15] ; // 用一个二维数组保存黑白子信息。 String show1 = "" ; // 默认黑方下棋 //默认下黑子 , 判断下什么棋子。bool=true 下黑子 ; bool=false 下白子 // boolean bool = true ; // 判断是否赢了比赛, 如果赢了比赛, 就不能再继续下棋了, boolean win =true ; public MyJFrame(){ int width = Toolkit.getDefaultToolkit().getScreenSize().width ; int height = Toolkit.getDefaultToolkit().getScreenSize().height ; this.setTitle("五子棋"); this.setResizable(false); this.setSize(500,550 ); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocation((width-500)/2 , (height-550)/2); this.repaint(); this.addMouseListener(this); try { buff = ImageIO.read(new File("e:/wzq.jpg" )); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.setVisible(true); }; // boolean rekai = true ; int select = 0 ; boolean bool2=true ; @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub // System.out.println(e.getX()); // System.out.println(e.getY()); } @Override public void mousePressed(MouseEvent e) { boolean bool = true ; for(int x = 0 ; x<15 ; x++){ for(int y = 0 ; y < 15 ; y++){ if(allChess[x][y]==0){ if(select==2){ bool = true ; }else if(select==1){ bool = false; } } } } if(win==true){ // TODO Auto-generated method stub x = e.getX(); y = e.getY(); if(x>=65&&x<=418&&y>=70&&y<=430){ x = (x-60)/25; //得到距离附近的交叉点X轴坐标 y = (y-70)/25; if(allChess[x][y]==0){ if(bool==true){ //默认下黑棋子先 allChess[x][y] =1; show1 = "白方下棋"; // 提示下步棋下白色 bool = false ; // 修改标记, 下步棋应该由白方下 select = 1 ; }else{ allChess[x][y]= 2 ; show1 = "黑方下棋"; bool = true; select = 2 ; } this.repaint(); int zong = 0 ; for(int i = 0 ; i < 15 ; i++ ){ for(int k = 0 ; k < 15 ; k++){ if(allChess[i][k]!=0){ zong++ ; } } } if(zong==225){ JOptionPane.showMessageDialog(this, "游戏平局,请点击“重新开始”重 新比过!"); } boolean heng1 = this.myCheck1() ; //横 false boolean heng2 = this.myCheck2() ; boolean heng3 = this.myCheck3() ; boolean heng4 = this.myCheck4() ; if(heng1==true||heng2==true||heng3==true||heng4==true){ JOptionPane.showMessageDialog(this,"游戏结束:" + (allChess[x][y]==1?"黑方":"白方")+"胜利"); win = false ; } } } } if(e.getX()>=427&&e.getX()<=495&&e.getY()>193&&e.getY()<228){ // 关于设计 JOptionPane.showMessageDialog(this, "本程序用JAVA设计") ; } if(e.getX()>=301&&e.getX()<=407&&e.getY()>466&&e.getY()<532){ // 重新开始 JOptionPane.showMessageDialog(this, "重新游戏") ; for(int i = 0 ; i < 15 ; i++ ){ for(int k = 0 ; k < 15 ; k++){ allChess[i][k] = 0 ; } } show1 = "" ; bool = true ; win =true ; select = 0 ; bool2 = true ; this.repaint() ; } if(e.getX()>=425&&e.getX()<=491&&e.getY()>101&&e.getY()<140){ // 设置设计 for(int x = 0 ; x<15 ; x++){ for(int y = 0 ; y < 15 ; y++){ if(allChess[x][y]==0&&select!=0){ bool2 = false ; } } } if(bool2==true){ String input = JOptionPane.showInputDialog( "选择谁先下棋:白方输入“1” ; 黑方输入 “2” ") ; try{ select = Integer.parseInt(input); if(select!=1&&select!=2){ JOptionPane.showMessageDialog(this, "您输入的不是1或2,请重新设置!"); select = 0; } }catch(Exception e1){ JOptionPane.showMessageDialog(this, "输入有误,请重新输入!"); } }else{ JOptionPane.showMessageDialog(this, "游戏比赛中,不能设置此项目!!!"); } } if(e.getX()>=426&&e.getX()<=495&&e.getY()>382&&e.getY()<425){ // 结束设计 int a = JOptionPane.showConfirmDialog(this, "游戏是否结束?") ; if(a==0){ System.exit(0); } if(a==1){ JOptionPane.showMessageDialog(this, "欢迎您回到游戏来!"); } if(a==2){ JOptionPane.showMessageDialog(this, "小样, 请别再耍我!"); } } if(e.getX()>=433&&e.getX()<=495&&e.getY()>289&&e.getY()<334){ //游戏说明 JOptionPane.showMessageDialog(this, "五子棋游戏规则: 谁先把5颗棋子相连,谁 就是赢家") ; } } public void paint(Graphics g){ BufferedImage B1 = new BufferedImage(500 , 550 ,BufferedImage.TYPE_INT_ARGB); // 定义一个新的缓冲图片 Graphics g2 = B1.createGraphics(); g2.drawImage(buff, 0, 20, this); // 将图片显示在窗体上 g2.setColor(Color.BLACK); // 设置画笔颜色为黑色 g2.fillOval(135, 144, 6, 6); g2.fillOval(334, 144, 6, 6); // 画几个定点 g2.fillOval(138, 342, 6, 6); g2.fillOval(334, 342, 6, 6); g2.fillOval(236, 242, 6, 6); g2.setFont(new Font("黑体" , Font.BOLD , 20)); g2.drawString("游戏信息:"+show1, 83, 49); //显示当前由哪一方下棋 g2.drawString("黑方:", 65, 473); g2.drawString("白方:", 62, 518); for(int i = 0 ; i < 15 ; i++ ){ // 循环判断 for(int j = 0 ; j < 15 ; j++){ if(allChess[i][j]==1){ //黑子 int tempX = i*25 + 63 ; int tempY = j*25 + 70 ; g2.fillOval(tempX-8, tempY-8, 16,16); } if(allChess[i][j]==2){ //白子 int tempX = i*25 + 63 ; int tempY = j*25 + 70 ; g2.setColor(Color.WHITE); g2.fillOval(tempX-8, tempY-8, 16,16); g2.setColor(Color.BLACK); g2.drawOval(tempX-8, tempY-8, 16, 16); } } } g.drawImage(B1, 0, 5, this); // 把B1这张图片在窗体显示出来 } public boolean myCheck1() { // 判断横向是否有五子相连 int count = 1; boolean heng = false ; // int color = allChess[x][y] ; // 判断颜色 // TODO Auto-generated method stub int i = 1 ; while(x+i<=14&&color == allChess[x+i][y]){ i++ ; count++ ; // System.out.println(count); //System.out.println(i); } i = 1 ; while(x-i>=0&&color == allChess[x-i][y]){ i++; count++ ; } if(count>=5){ heng = true ; } return heng ; } public boolean myCheck2() { // 判断纵向是否有五子相连 int count = 1; boolean zhong = false ; int color = allChess[x][y] ; // TODO Auto-generated method stub int i = 1 ; while((y+i)<=14&&color == allChess[x][y+i]){ i++ ; count++ ; } i = 1 ; while((y-i)>=0&&color == allChess[x][y-i]){ i++; count++ ; } if(count>=5){ zhong = true ; } return zhong ; } public boolean myCheck3() { // 判断右斜向是否有五子相连 int count = 1; boolean zhong = false ; int color = allChess[x][y] ; // TODO Auto-generated method stub int i = 1 ; while((x+i)<=14&&(y-i)>=0&&color == allChess[x+i][y-i]){ i++ ; count++ ; } i = 1 ; while((x-i)>=0&&(y+i)<=14&&color == allChess[x-i][y+i]){ i++; count++ ; } if(count>=5){ zhong = true ; } return zhong ; } public boolean myCheck4() { // 判左斜向是否有五子相连 int count = 1; boolean zhong = false ; int color = allChess[x][y] ; // TODO Auto-generated method stub int i = 1 ; while((x-i)>=0&&(y-i)>=0&&color == allChess[x-i][y-i]){ i++ ; count++ ; } i = 1 ; while((x+i)<=14&&(y+i)<=14&&color == allChess[x+i][y+i]){ i++; count++ ; } if(count>=5){ zhong = true ; } return zhong ; } @Override public void mouseReleased(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 } } Text01.java package chi1.Text; import chi1.JFrame.MyJFrame; public class Text01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MyJFrame jf = new MyJFrame() ; // String b1 = JOptionPane.showInputDialog("请输入你的名字:") ; //int b = JOptionPane.showConfirmDialog(jf, "我的信息:" + b1); } }

javadevelopmentisnotentirelyplatform-IndectionentDuetoSeveralFactors.1) JVMVARIATIONSAFFERFFERFORMANDBEHAVIORACROSSDIFFERENTOS.2) nativelibrariesViajniintrictionPlatform-specificiss.3) filepathsandsystempropertiesdifferbetweenplatectry. 4)

Java 코드는 다른 플랫폼에서 실행할 때 성능 차이가 있습니다. 1) JVM의 구현 및 최적화 전략은 OracleJDK 및 OpenJDK와 같이 다릅니다. 2) 메모리 관리 및 스레드 스케줄링과 같은 운영 체제의 특성도 성능에 영향을 미칩니다. 3) 적절한 JVM을 선택하여 JVM 매개 변수 및 코드 최적화를 조정하여 성능을 향상시킬 수 있습니다.

Java'SplatformIndenceHASLIMITATIONSINTERFORMANTOWORHEAD, 버전 컴포팅 가능성, 도전 과제, 플랫폼-특이 적 식품, 및 JVMINSTALLATION/MAYMENDENT.ThesefacteThe "WriteOnce, Runanywhere"

Platform IndependenCealLowsProgramStorunannyplatformwithoutModification, whileCross-PlatformDevelopmentRequiressomplatformspecificAdJustments.platformIndence, PreemplifiedByjava, enableStalExecutionButmayPromiseperformance.cross-platformd

jitcompilationinjavaenhancesperformance는 platformindence.1) ItdynamicallyTransLatesByTecodeIntonativeMachinecodeatimeTime, 최적화 FREQUELTEREDCODE.2) TheJVMREMAINSPLATFORM- Independent, 허용 THEMEJAVAAPPLITIONTORUNONDIFFEREN을 허용합니다

javaispopularforcross-platformdesktopapplicationsduetoits "writeonce, runanywhere"철학

Java에서 플랫폼 별 코드를 작성하는 이유에는 특정 운영 체제 기능에 대한 액세스, 특정 하드웨어와 상호 작용하고 성능 최적화가 포함됩니다. 1) JNA 또는 JNI를 사용하여 Windows 레지스트리에 액세스하십시오. 2) JNI를 통한 Linux 특이 적 하드웨어 드라이버와 상호 작용; 3) 금속을 사용하여 JNI를 통해 MacOS의 게임 성능을 최적화하십시오. 그럼에도 불구하고 플랫폼 별 코드를 작성하면 코드의 이식성에 영향을 미치고 복잡성을 높이며 잠재적으로 성능 오버 헤드 및 보안 위험을 초래할 수 있습니다.

Java는 Cloud-Native Applications, Multi-Platform 배포 및 교차 운용성을 통해 플랫폼 독립성을 더욱 향상시킬 것입니다. 1) Cloud Native Applications는 Graalvm 및 Quarkus를 사용하여 시작 속도를 높입니다. 2) Java는 임베디드 장치, 모바일 장치 및 양자 컴퓨터로 확장됩니다. 3) Graalvm을 통해 Java는 Python 및 JavaScript와 같은 언어와 완벽하게 통합되어 언어 교차 수용 가능성을 향상시킵니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

Dreamweaver Mac版
시각적 웹 개발 도구
