成都网站建设设计

将想法与焦点和您一起共享

java中小程序代码 小程序编程代码

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

import java.awt.*;

成都创新互联公司长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为麻章企业提供专业的成都网站设计、网站建设,麻章网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

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经典小程序代码

代码如下:

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写一个小程序

java实现先输入10个int类型的参数,之后循环判断找到最大值和最小值,保存起来和其他的值进行比较。代码如下:

public class Test{

public static void main(String args[]){

int i,min,max;

int A[] = new int[10];

Scanner input=new Scanner(System.in);

for(int j=0,j10;j++){//输入10个数

System.out.println("请输入一个数字:");

int length=input.nextInt();//输入一个数字

A[i] =length;

}

min=max=A[0];

System.out.print("数组A的元素包括:");

int j =0;

int n =0 ;

for(i=0;iA.length;i++)

{

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

if(A[i]max) // 判断最大值

j =i;

max=A[i];

if(A[i]min) // 判断最小值

min=A[i];

n =i

}

System.out.println("\n数组的最大值是:"+max+".数组的位置是:"+(j+1)); // 输出最大值和最大值的位置

System.out.println("数组的最小值是:"+min+".数组的位置是:"+(n+1)); // 输出最小值

}

}

谁能给个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中小程序代码 小程序编程代码
网站路径:http://chengdu.cdxwcx.cn/article/docipcj.html