求一个java applet小程序的源代码

求一个java applet小程序的源代码,第1张

import java.applet.Applet

import java.awt.Button

import java.awt.Color

import java.awt.Graphics

import java.awt.TextField

import java.awt.event.ActionEvent

public class Nicki extends Applet{

private static final long serialVersionUID = 瞎此1L

private Button ok

private int num=32

private int resu=0

private boolean isRig=false

private TextField iPut

public Nicki(){

this.setLayout(null)

ok=new Button("OK")

ok.setActionCommand(getName())

ok.setBounds(150, 150, 40, 20)

iPut=new TextField()

this.add(iPut)

iPut.setBounds(100, 150, 40, 20)

this.add(ok)

ok.addActionListener(new ButtonAction(this))

}

public void paint(Graphics g){

g.setColor(Color.white)

g.fillRect(0, 0, this.getWidth(), this.getHeight())

g.setColor(Color.BLACK)

g.drawString("Please guess a number ", 10, 20)

g.drawString("between 1 and 100", 10, 40)

if(isRig==false&&坦裤resu!=0){

if(resu>num){

g.drawString(""+resu+" is too big !", 10, 100)

}else if(resu<num){

g.drawString(resu+"is too small !", 10, 100)

}

}else if(isRig==true){

g.setColor(Color.GREEN)

g.drawString("Yes,"+resu+" is the 磨信迅right number", 10, 80)

g.drawString("Your are great! ", 10, 100)

g.setColor(Color.red)

g.drawString(resu+"!", 70, 120)

}

iPut.setText("")

g.drawString("Input the number:", 0, 150)

}

public void ButtonActionPerformed(ActionEvent e){

if(e.getActionCommand().equals("panel0")){

resu=Integer.parseInt(iPut.getText())

if(num==resu){

isRig=true

}else{

isRig=false

}

repaint()

}

}

}

class ButtonAction implements java.awt.event.ActionListener{

Nicki su

public ButtonAction(Nicki bun){

this.su=bun

}

public void actionPerformed(ActionEvent e) {

su.ButtonActionPerformed(e)

}

}

1.注册小程序平台。

2.认证之后,创建小程序,设定好名称后会得到appid和应用密匙。

3.下载微信小李没陆程序开发者工具,创建项目,将appid填入和项目名称填入,选择小程序源码的目录,点击打开。

4.打开后就能在开发者工具里面看到小程序源码的察凯形态了,哪顷确定无误后,点上传到小程序后台。

5.提交后,在小程序后台有一个开发版本,点击它,提交审核,等待审核通过即可发布了。

也不知埋拦道你具体需求是什么,以前改过一个日历程序,一共四个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 = 1i <= mFristWeeki++){

str += " \t"

}

for (int j = 1j <= mDayOfMonthj++, 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 = 1990i<=2025i++) {

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("日期数据不合法.")

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8273317.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存