java项目小程序代码 java项目小程序代码有哪些

求java小程序代码,500行左右。。大作业用。追加50

import java.awt.*;

创新互联专注于宝鸡网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供宝鸡营销型网站建设,宝鸡网站制作、宝鸡网页设计、宝鸡网站官网定制、成都微信小程序服务,打造宝鸡网络公司原创品牌,更为您提供宝鸡网站排名全网营销落地服务。

import java.awt.event.*;

import javax.swing.*;

class mypanel extends Panel implements MouseListener

{

int chess[][] = new int[11][11];

boolean Is_Black_True;

mypanel()

{

Is_Black_True = true;

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

chess[i][j] = 0;

}

}

addMouseListener(this);

setBackground(Color.BLUE);

setBounds(0, 0, 360, 360);

setVisible(true);

}

public void mousePressed(MouseEvent e)

{

int x = e.getX();

int y = e.getY();

if(x 25 || x 330 + 25 ||y 25 || y 330+25)

{

return;

}

if(chess[x/30-1][y/30-1] != 0)

{

return;

}

if(Is_Black_True == true)

{

chess[x/30-1][y/30-1] = 1;

Is_Black_True = false;

repaint();

Justisewiner();

return;

}

if(Is_Black_True == false)

{

chess[x/30-1][y/30-1] = 2;

Is_Black_True = true;

repaint();

Justisewiner();

return;

}

}

void Drawline(Graphics g)

{

for(int i = 30;i = 330;i += 30)

{

for(int j = 30;j = 330; j+= 30)

{

g.setColor(Color.WHITE);

g.drawLine(i, j, i, 330);

}

}

for(int j = 30;j = 330;j += 30)

{

g.setColor(Color.WHITE);

g.drawLine(30, j, 330, j);

}

}

void Drawchess(Graphics g)

{

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

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

{

g.setColor(Color.BLACK);

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

}

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

{

g.setColor(Color.WHITE);

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

}

}

}

}

void Justisewiner()

{

int black_count = 0;

int white_count = 0;

int i = 0;

for(i = 0;i 11;i++)//横向判断

{

for(int j = 0;j 11;j++)

{

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

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

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

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 11;i++)//竖向判断

{

for(int j = 0;j 11;j++)

{

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

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

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

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 7;i++)//左向右斜判断

{

for(int j = 0;j 7;j++)

{

for(int k = 0;k 5;k++)

{

if(chess[i + k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i + k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

for(i = 4;i 11;i++)//右向左斜判断

{

for(int j = 6;j = 0;j--)

{

for(int k = 0;k 5;k++)

{

if(chess[i - k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i - k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

}

void Clear_Chess()

{

for(int i=0;i11;i++)

{

for(int j=0;j11;j++)

{

chess[i][j]=0;

}

}

repaint();

}

public void paint(Graphics g)

{

Drawline(g);

Drawchess(g);

}

public void mouseExited(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseReleased(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

}

class myframe extends Frame implements WindowListener

{

mypanel panel;

myframe()

{

setLayout(null);

panel = new mypanel();

add(panel);

panel.setBounds(0,23, 360, 360);

setTitle("单人版五子棋");

setBounds(200, 200, 360, 383);

setVisible(true);

addWindowListener(this);

}

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

public void windowDeactivated(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

}

public class mywindow

{

public static void main(String argc [])

{

myframe f = new myframe();

}

}

谁能给个JAVA的小程序代码,越小越好!

这是我晓得的最简单的java小程序代码了你可以看看:

package com.kenki.emp;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.SQLException;

import java.sql.*;

public class emp extends HttpServlet {

private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables

public void init() throws ServletException {

}

//Process the HTTP Get request

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

response.setContentType(CONTENT_TYPE);

PrintWriter out = response.getWriter();

String code = request.getParameter("code");

String name = request.getParameter("name");

String pay = request.getParameter("pay");

System.out.println("empcode:" + code);

System.out.println("name:" + name);

System.out.println("pay:" + pay);

//创建驱动

new com.microsoft.jdbc.sqlserver.SQLServerDriver();

String strd =

"jdbc:microsoft:sqlserver://localhost:1433;databasename=emp_dates";

String username = "sa";

String pws = "";

try {

java.sql.Connection conn = java.sql.DriverManager.getConnection(

strd, username, pws);

String strs = "insert into emp values(?,?,?)";

java.sql.PreparedStatement pre = conn.prepareStatement(strs);

pre.setString(1, code);

pre.setString(2, name);

pre.setString(3, pay);

pre.execute();

pre.close();

conn.close();

//重定向至查询页面

out.println("成功保存!!");

response.sendRedirect("emp.html");

} catch (SQLException ss) {

ss.printStackTrace();

response.sendRedirect("/WebModule1/error.html");

}

}

//Process the HTTP Post request

public void doPost(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

doGet(request, response);

}

//Clean up resources

public void destroy() {

}

}

求java经典小程序代码

代码如下:

public class HelloWorld {

public static void main(String []args) {

int a = 3, b = 7 ;

 System.out.println("Hello World!");

}

public static int f(int a, int b){

return a*a + a*b + b*b;

}

}

结果如下:

用java编一个小程序

import java.io.*;

public class BaiduJava

{

public static int[] input(String arg)

{

int n=Integer.parseInt(arg);

int i=0;

int a[]=new int[n];

while(in)

{

System.out.print("input "+(i+1)+" number :");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try

{

a[i]=Integer.parseInt(br.readLine());

}

catch(Exception e)

{

System.out.println(e.getMessage());

}

i++;

}

return a;

}

public static int[] sort(int[] a)

{

for(int i=0;ia.length-1;i++)

{

for(int j=i+1;ja.length;j++)

{

int t;

if(a[i]a[j])

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

}

return a;

}

public static void main(String[] args)

{

int[] b=sort(input(args[0]));

for(int i=0;ib.length;i++)

System.out.print(b[i]+" ");

System.out.println();

}

}

运行过了,没问题。命令行第一个参数输入n

标题名称:java项目小程序代码 java项目小程序代码有哪些
网页路径:https://www.cdcxhl.com/article20/dodddco.html

成都网站建设公司_创新互联,为您提供面包屑导航网站设计公司用户体验建站公司商城网站品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管