RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
小程序的java代码,java小程序源码

求java经典小程序代码

代码如下:

创新互联为企业级客户提高一站式互联网+设计服务,主要包括网站建设、网站设计app软件定制开发重庆小程序开发公司、宣传片制作、LOGO设计等,帮助客户快速提升营销能力和企业形象,创新互联各部门都有经验丰富的经验,可以确保每一个作品的质量和创作周期,同时每年都有很多新员工加入,为我们带来大量新的创意。 

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小程序代码,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();

}

}

小程序后台获取openId解密的java代码怎么写

一、获取code

将code作为参数传递过来

//如果有code,说明是微信小程序,根据code获取openId

//classify用于标识是哪个小程序

if (!CheckUtil.checkNulls( keUser.getCode(),keUser.getClassify())){

//

String openid = OpenIdUtil.oauth2GetOpenid(keUser.getCode(),keUser.getClassify());

printParamsLog(openid, logger);

keUser.setUserId(openid);

}1234567812345678

二、工具类

package com.util;

import net.sf.json.JSONObject;

import org.apache.http.client.HttpClient;

import org.apache.http.client.ResponseHandler;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.BasicResponseHandler;

import org.apache.http.impl.client.DefaultHttpClient;

import java.util.HashMap;

import java.util.Map;

/**

* @author xsx

*/

public class OpenIdUtil {

public static String oauth2GetOpenid(String code,String classify) {

String appid="";

String appsecret="";

switch (classify){

case "1":

//自己的配置appid

appid = "**********";

//自己的配置APPSECRET;

appsecret = "**********";

break;

case "2":

appid = "**********";

appsecret = "************";

break;

case "3":

appid = "**********";

appsecret = "************";

break;

case "4":

appid = "**********";

appsecret = "************";

break;

case "5":

appid = "**********";

appsecret = "************";

}

//授权(必填)

String grant_type = "authorization_code";

//URL

String requestUrl = "";

//请求参数

String params = "appid=" + appid + "secret=" + appsecret + "js_code=" + code + "grant_type=" + grant_type;

//发送请求

String data = HttpUtil.get(requestUrl, params);

//解析相应内容(转换成json对象)

JSONObject json = JSONObject.fromObject(data);

//用户的唯一标识(openid)

String Openid =String.valueOf(json.get("openid"));

//System.out.println(Openid);

return Openid;

}

}

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960

三、发送请求的工具类

package com.util;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.URL;

import java.net.URLConnection;

import java.util.List;

import java.util.Map;

/**

* @author xsx

*/

public class HttpUtil {

/**

* 向指定URL发送GET方法的请求

*

* @param url

* 发送请求的URL

* @param param

* 请求参数,请求参数应该是 name1=value1name2=value2 的形式。

* @return String 所代表远程资源的响应结果

*/

public static String get(String url,String param){

String result = "";

BufferedReader in = null;

try {

String urlNameString = url + "?" + param;

//System.out.println(urlNameString);

URL realUrl = new URL(urlNameString);

// 打开和URL之间的连接

URLConnection connection = realUrl.openConnection();

// 设置通用的请求属性

connection.setRequestProperty("accept", "*/*");

connection.setRequestProperty("connection", "Keep-Alive");

connection.setRequestProperty("user-agent",

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

// 建立实际的连接

connection.connect();

// 获取所有响应头字段

MapString, ListString map = connection.getHeaderFields();

// 遍历所有的响应头字段

/*for (String key : map.keySet()) {

System.out.println(key + "---" + map.get(key));

}*/

// 定义 BufferedReader输入流来读取URL的响应

in = new BufferedReader(new InputStreamReader(

connection.getInputStream()));

String line;

while ((line = in.readLine()) != null) {

result += line;

}

} catch (Exception e) {

System.out.println("发送GET请求出现异常!" + e);

e.printStackTrace();

}

// 使用finally块来关闭输入流

finally {

try {

if (in != null) {

in.close();

}

} catch (Exception e2) {

e2.printStackTrace();

}

}

return result;

}

}

求Java 日历的小程序的源代码

也不知道你具体需求是什么,以前改过一个日历程序,一共四个java类,放在同一个包里。经测试可以运行。

//Start.java

import java.awt.*;

import javax.swing.*;

class Start{

public static void main(String [] args){

DateFrame frame=new DateFrame();

frame.setLocationRelativeTo(frame);

frame.setResizable(false);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

}

//DateInfo.java

import java.util.*;

public class DateInfo{

private int mYear, mMonth;

private int mDayOfMonth, mFristWeek;

public DateInfo(int year, int month) throws DateException{

mYear = year;

if (month 0 || month 12){

throw (new DateException());

}

mMonth = month;

mDayOfMonth = getDayOfMonth(mYear, mMonth);

mFristWeek = getFristWeek(mYear, mMonth);

}

private int getDayOfMonth(int year, int month){

int[][] ary = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

return (ary[isLeapYear(year)][month]);

}

private int isLeapYear(int year){

if (year % 4 == 0 year % 100 != 0 ||year % 400 == 0){

return (1);

}

else{

return (0);

}

}

private int getFristWeek(int year, int month){

java.util.Calendar cal = Calendar.getInstance();

cal.set(year, month - 1, 1);

return (cal.get(Calendar.DAY_OF_WEEK) - 1);

}

public String toString(){

String str;

str = "\t\t" + mYear + "年" + mMonth + "月\n";

str += "日\t一\t二\t三\t四\t五\t六\n";

int i;

for (i = 1; i = mFristWeek; i++){

str += " \t";

}

for (int j = 1; j = mDayOfMonth; j++, i++){

str +=j+"\t" ;

if (i % 7 == 0){

str += "\n";

}

}

return (str);

}

}

//DateFrame.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.Calendar;

class DateFrame extends JFrame implements Runnable{

Calendar date=Calendar.getInstance();

String[] str={"1","2","3","4","5","6","7","8","9","10","11","12"};

JLabel lblYear=new JLabel("年 ");

JLabel lblMonth=new JLabel("月 ");

JLabel lblDate=new JLabel("现在的时间是:");

JLabel lblShowDate=new JLabel();

// javax.swing.JTextField trxt =new JTextField(10);

// trxt.setHorizontalAlignment(JTextField.RIGHT); //设置文本从右边输入

JComboBox cboMonth=new JComboBox(str);

JComboBox cboYear=new JComboBox();

JTextArea txaShow=new JTextArea();

JPanel pnlNorth=new JPanel();

JPanel pnlSOUTH=new JPanel();

JButton btnShow=new JButton("显示");

JButton btnClose=new JButton("关闭");

JScrollPane jsp=new JScrollPane(txaShow);

Container c=this.getContentPane();

public DateFrame(){

Thread thread=new Thread(this);

thread.start();

this.setTitle("玩玩日历拉!!!");

this.setSize(300,260);

for (int i = 1990; i=2025; i++) {

cboYear.addItem(""+i);

}

cboYear.setSelectedItem(""+(date.get(Calendar.YEAR)));

cboMonth.setSelectedItem(""+(date.get(Calendar.MONTH)+1));

pnlNorth.add(cboYear);

txaShow.setTabSize(4); //设置tab键的距离

txaShow.setForeground(Color.GREEN);

pnlNorth.add(lblYear);

pnlNorth.add(cboMonth);

pnlNorth.add(lblMonth);

pnlNorth.add(lblDate);

pnlNorth.add(lblShowDate);

c.add(pnlNorth,BorderLayout.NORTH);

c.add(jsp);

pnlSOUTH.add(btnShow);

pnlSOUTH.add(btnClose);

c.add(pnlSOUTH,BorderLayout.SOUTH);

btnShow.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

int year=Integer.parseInt((String)cboYear.getSelectedItem());

int month=Integer.parseInt((String)cboMonth.getSelectedItem());

try {

DateInfo date=new DateInfo(year,month);

txaShow.setText(""+date);

}

catch (DateException ex) {

ex.printStackTrace();

}

}

});

btnClose.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

System.exit(0);

}

});

}

public void run(){

try {

while(true){

Thread.sleep(1000);

int hour=date.get(Calendar.HOUR);

int minute=date.get(Calendar.MINUTE);

int second=date.get(Calendar.SECOND);

String str=hour+":"+minute+":"+second;

lblShowDate.setText(str);

//this.repaint();

}

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}

//DateException.java

public class DateException extends Exception{

public DateException(){

super("日期数据不合法.");

}

}

急求小程序,用JAVA编写

import java.util.Scanner;

public class NumberConvertor {

/**

* @param args

*/

public int input() {

Scanner scan = new Scanner(System.in);

int inputInt = 0;

while (true) {

try {

System.out.println("输入一个0-100的正整数(默认为0): ");

inputInt = scan.nextInt();

if (inputInt 0 || inputInt = 100) {

System.out.println("越界");

continue;

} else {

break;

}

} catch (Exception e) {

System.out.println("输入有误,重新输入");

break;

}

}

return inputInt;

}

public String convert(int aInt) {

String[] table = new String[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒",

"捌", "玖", "拾" };

String result;

String left;

String right;

int leftInt;

int rightInt;

if (aInt = 10) {

result = table[aInt];

} else {

leftInt = Integer.parseInt((String.valueOf(aInt)).substring(0, 1));

rightInt = Integer.parseInt((String.valueOf(aInt)).substring(1));

left = table[leftInt];

right = table[rightInt];

result = left + table[10] + right;

}

return result;

}

public static void main(String[] args) {

NumberConvertor nc = new NumberConvertor();

int val;

val = nc.input();

System.out.println(nc.convert(val));

}

}

java小程序编写

楼主,以下是我的实现方式,看看是不是你想要的,哪里不清楚的可以单独M我。

import java.util.Arrays;

import java.util.Comparator;

public class Student {

private int id;

private String name;

private String birthday;

public Student(int id, String name, String birthday) {

this.id = id;

this.name = name;

this.birthday = birthday;

}

public static void main(String[] args) {

Student s1 = new Student(1, "张三", "1983-01-22");

Student s2 = new Student(2, "张一", "1983-01-21");

Student s3 = new Student(3, "张笑一", "1983-01-27");

Student s4 = new Student(4, "张含一", "1983-01-01");

Student[] students = { s1, s2, s3, s4 }; //将4个学生对象装入数组中

//现根据出生日期对数组元素进行排序,由于String已经实现了Comparable接口,可以直接利用compareTo方法进行比较

Arrays.sort(students, new ComparatorStudent() {

public int compare(Student o1, Student o2) {

return o1.getBirthday().compareTo(o2.getBirthday());

}

});

//打印排序后的结构

System.out.println(Arrays.toString(students));

Student[] newStudents = new Student[students.length];

int i = 0;

for (Student s : students) {

if (s.getName().indexOf("一") != -1) {

newStudents[i] = s;

i++;

}

}

//打印搜索出的姓名含“一”的学生

System.out.println(Arrays.toString(newStudents));

}

@Override

public String toString() {

// TODO 自动生成方法存根

return "Student姓名:" + this.name + ",出生日期:" + this.birthday;

}

public int getId() {

return id;

}

public String getName() {

return name;

}

public void setId(int id) {

this.id = id;

}

public void setName(String name) {

this.name = name;

}

public String getBirthday() {

return birthday;

}

public void setBirthday(String birthday) {

this.birthday = birthday;

}

}


网页题目:小程序的java代码,java小程序源码
本文地址:http://scyingshan.cn/article/hcejgh.html