你好,java实现开发答题小程序首先要明确您的需求,目前市面上的答题小程序均是在微擎框架基础上开发的应用,比如挑战答题王等,但这有个弊端就是针对开发者来说无法更好进行二次开发,无法按用户的需求实现各类答题模式需求。敬请采纳:上效果图
答题小程序主页面
释义:通过上面的效果图我们可以看到java技术实现的答题小程序,答题模式是比较丰富的,包括:签到、赛季、每日答题、好友PK、排位升级、团队多人赛、还有道具背包等
2、然后我们看一下这里的代码形式:
答题小程序开发界面
上述我们可以看到,小程序端是原生开发的,非h5打包,这样就能满足了原生小程序的流程性。
3、然后我们看一下管理后台
给你一个简单的实现吧,注意一定要先运行MyServerjava
//MyCilentjava
import javaio;
import javanet;
import javaxswing;
import javaawt;
import javaawtevent;
public class MyClient extends JFrame implements ActionListener{
JTextField tf;
JTextArea tx;
JButton bt;
PrintWriter out;
public MyClient(){
tf=new JTextField(20);
tx=new JTextArea();
txsetLineWrap(true);
txsetWrapStyleWord(true);
JPanel pan=new JPanel();
JScrollPane jsp=new JScrollPane(tx);
add(jsp,"Center");
bt=new JButton("SEND");
btaddActionListener(this);
panadd(tf);
panadd(bt);
add(pan,"South");
thisaddWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Systemexit(0);
}
});
setTitle("THE CLIENT");
setSize(400,300);
setVisible(true);
try{
Socket socket=new Socket("127001",1680);
out=new PrintWriter(socketgetOutputStream(),true);
InputStreamReader in = new InputStreamReader(socketgetInputStream());
BufferedReader sin=new BufferedReader(in);
String s;
while(true){
s=sinreadLine();
txappend("#Server Said#: "+s+"\n");
}
}catch(Exception e){
eprintStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(egetSource()==bt){
txappend("@Client Said@: "+tfgetText()+"\n");
outprintln(tfgetText());
tfsetText("");
}
}
public static void main(String[] args){
MyClient mct = new MyClient();
}
}
//MyServerjava
import javaio;
import javanet;
import javaxswing;
import javaawt;
import javaawtevent;
public class MyServer extends JFrame implements ActionListener{
JTextField tf;
JTextArea tx;
JButton bt;
JScrollPane jsp;
JPanel pan;
PrintWriter out;
public MyServer(){
tx=new JTextArea();
txsetLineWrap(true);
txsetWrapStyleWord(true);
jsp=new JScrollPane(tx);
tf=new JTextField(20);
bt=new JButton("SEND");
btaddActionListener(this);
pan=new JPanel();
panadd(tf);
panadd(bt);
add(pan,"South");
add(jsp,"Center");
thisaddWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Systemexit(0);
}
});
setTitle("THE SERVER");
setSize(400,300);
setVisible(true);
try{
ServerSocket server = new ServerSocket(1680);
Socket socket = serveraccept();
InputStreamReader in = new InputStreamReader(socketgetInputStream());
BufferedReader sin=new BufferedReader(in);
out=new PrintWriter(socketgetOutputStream(),true);
while(true){
String s=sinreadLine();
txappend("@Client Said@: "+s+"\n");
}
}catch(Exception e){
eprintStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(egetSource()==bt){
String st = tfgetText();
txappend("#Server Said#: "+st+"\n");
outprintln(st);
tfsetText("");
}
}
public static void main(String[] args){
MyServer msr = new MyServer();
}
}
这是我编过的程序
它用来计算两个日期之间间隔
某日期向前/后几天是什么日期(考虑闰年)
星期几不好算,肯定要找个基准点
import javaawt;
import javaawtevent;
public class dakiler
{
public static void main(String args[])
{
new mainpage();
}
}
class mainpage extends Frame implements ActionListener
{
private Button button2,button3,button4;
forward frame1;
backward frame2;
twodates frame3;
mainpage()
{
super("主选择页面");
thissetLayout(new FlowLayout());
thissetLocation(250,250);
button2=new Button("日期向后计算");
button3=new Button("日期向前计算");
button4=new Button("两个日期计算");
button2addActionListener(this);
button3addActionListener(this);
button4addActionListener(this);
thisadd(button2);
thisadd(button3);
thisadd(button4);
thisaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
Systemexit(0);
}
}
);
thispack();
thisshow();
}
public void actionPerformed(ActionEvent e)
{
if(egetSource()==button2)
{
thissetLocation(0,0);
forward frame1=new forward();
}
if(egetSource()==button3)
{
thissetLocation(0,0);
backward frame2=new backward();
}
if(egetSource()==button4)
{
thissetLocation(0,0);
twodates frame3=new twodates();
}
thispack();
}
}
/
class mainpage extends Frame implements ItemListener
{
private Choice choice;
private Label label1;
forward frame1;
backward frame2;
twodates frame3;
mainpage () {
thissetLayout(null);
thissetBounds(250,250,150,90);
choice=new Choice();
label1=new Label("请选择");
choiceaddItem("日期向后计算");
choiceaddItem("日期向前计算");
choiceaddItem("两个日期计算");
choiceaddItemListener(this);
label1setBounds(20,30,100,20);
choicesetBounds(20,50,100,20);
thisadd(label1);
thisadd(choice);
thisaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
Systemexit(0);
}
}
);
thisshow();
}
public void itemStateChanged(ItemEvent e)
{
if(choicegetSelectedItem()equals("日期向后计算"))
{
thissetLocation(0,0);
if (frame1!=null) frame1dispose();
if (frame2!=null) frame2dispose();
if (frame3!=null) frame3dispose();
frame1=new forward();
}
if(choicegetSelectedItem()equals("日期向前计算"))
{
thissetLocation(0,0);
if (frame1!=null) frame1dispose();
if (frame2!=null) frame2dispose();
if (frame3!=null) frame3dispose();
frame2=new backward();
}
if(choicegetSelectedItem()equals("两个日期计算"))
{
thissetLocation(0,0);
if (frame1!=null) frame1dispose();
if (frame2!=null) frame2dispose();
if (frame3!=null) frame3dispose();
frame3=new twodates();
}
}
}
class forward extends Frame implements ActionListener
{
private Button button5,button6;
private TextField yeartextfield,monthtextfield,daytextfield,timetextfield,answertextfield;
private Label yearlabel,monthlabel,daylabel,timelabel,answerlabel;
private double year,month,day,time;
private boolean isren,iscontinue;
forward()
{
super("日期向后计算");
thissetLayout(null);
thissetBounds(0,250,800,150);
thissetResizable(false);
button5=new Button("确定");
button6=new Button("清除");
yearlabel=new Label("请输入年份");
monthlabel=new Label("请输入月份");
daylabel=new Label("请输入日期");
timelabel=new Label("请输入向后几天");
answerlabel=new Label("答案是");
yeartextfield=new TextField(5);
monthtextfield=new TextField(5);
daytextfield=new TextField(5);
timetextfield=new TextField(5);
answertextfield=new TextField(20);
button5addActionListener(this);
button6addActionListener(this);
yeartextfieldaddActionListener(this);
monthtextfieldaddActionListener(this);
daytextfieldaddActionListener(this);
timetextfieldaddActionListener(this);
yearlabelsetBounds(0,50,100,20);
yeartextfieldsetBounds(100,50,100,20);
monthlabelsetBounds(0,80,100,20);
monthtextfieldsetBounds(100,80,100,20);
daylabelsetBounds(0,110,100,20);
daytextfieldsetBounds(100,110,100,20);
timelabelsetBounds(200,80,100,20);
timetextfieldsetBounds(300,80,100,20);
button5setBounds(400,80,100,20);
button6setBounds(500,80,100,20);
answerlabelsetBounds(600,80,100,20);
answertextfieldsetBounds(700,80,100,20);
thisadd(yearlabel);
thisadd(yeartextfield);
thisadd(monthlabel);
thisadd(monthtextfield);
thisadd(daylabel);
thisadd(daytextfield);
thisadd(timelabel);
thisadd(timetextfield);
thisadd(button5);
thisadd(button6);
thisadd(answerlabel);
thisadd(answertextfield);
thisaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
);
thisshow();
}
public void actionPerformed(ActionEvent e)
{
if (egetSource()==button6)
{
yeartextfieldsetText("");
monthtextfieldsetText("");
daytextfieldsetText("");
timetextfieldsetText("");
answertextfieldsetText("");
}
else if((egetSource()==button5)||(egetSource()==yeartextfield)||(egetSource()==monthtextfield)||(egetSource()==daytextfield)||(egetSource()==timetextfield))
{
try
{
year=DoubleparseDouble(yeartextfieldgetText());
month=DoubleparseDouble(monthtextfieldgetText());
day=DoubleparseDouble(daytextfieldgetText());
time=DoubleparseDouble(timetextfieldgetText());
}
catch (Exception exc)
{
iscontinue=false;
answertextfieldsetText("输入不正确");
}
function func=new function();
isren=funcren(year);
iscontinue=false;
iscontinue=funcconti(month,day,isren);
if(iscontinue)
{
String str=funcplus(year,month,day,time);
answertextfieldsetText(str);
}
else
{ answertextfieldsetText("输入不正确");
}
}
}
}
class backward extends Frame implements ActionListener
{
private Button button5,button6;
private TextField yeartextfield,monthtextfield,daytextfield,timetextfield,answertextfield;
private Label yearlabel,monthlabel,daylabel,timelabel,answerlabel;
private double year,month,day,time;
private boolean isren,iscontinue;
backward()
{
super("日期向前计算");
thissetLayout(null);
thissetBounds(0,250,800,150);
thissetResizable(false);
button5=new Button("确定");
button6=new Button("清除");
yearlabel=new Label("请输入年份");
monthlabel=new Label("请输入月份");
daylabel=new Label("请输入日期");
timelabel=new Label("请输入向前几天");
answerlabel=new Label("答案是");
yeartextfield=new TextField(5);
monthtextfield=new TextField(5);
daytextfield=new TextField(5);
timetextfield=new TextField(5);
answertextfield=new TextField(20);
button5addActionListener(this);
button6addActionListener(this);
yeartextfieldaddActionListener(this);
monthtextfieldaddActionListener(this);
daytextfieldaddActionListener(this);
timetextfieldaddActionListener(this);
yearlabelsetBounds(0,50,100,20);
yeartextfieldsetBounds(100,50,100,20);
monthlabelsetBounds(0,80,100,20);
monthtextfieldsetBounds(100,80,100,20);
daylabelsetBounds(0,110,100,20);
daytextfieldsetBounds(100,110,100,20);
timelabelsetBounds(200,80,100,20);
timetextfieldsetBounds(300,80,100,20);
button5setBounds(400,80,100,20);
button6setBounds(500,80,100,20);
answerlabelsetBounds(600,80,100,20);
answertextfieldsetBounds(700,80,100,20);
thisadd(yearlabel);
thisadd(yeartextfield);
thisadd(monthlabel);
thisadd(monthtextfield);
thisadd(daylabel);
thisadd(daytextfield);
thisadd(timelabel);
thisadd(timetextfield);
thisadd(button5);
thisadd(button6);
thisadd(answerlabel);
thisadd(answertextfield);
thisaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
);
thisshow();
}
public void actionPerformed(ActionEvent e)
{
if (egetSource()==button6)
{
yeartextfieldsetText("");
monthtextfieldsetText("");
daytextfieldsetText("");
timetextfieldsetText("");
answertextfieldsetText("");
}
else if((egetSource()==button5)||(egetSource()==yeartextfield)||(egetSource()==monthtextfield)||(egetSource()==daytextfield)||(egetSource()==timetextfield))
{
try
{
year=DoubleparseDouble(yeartextfieldgetText());
month=DoubleparseDouble(monthtextfieldgetText());
day=DoubleparseDouble(daytextfieldgetText());
time=DoubleparseDouble(timetextfieldgetText());
}
catch (Exception exc)
{
iscontinue=false;
answertextfieldsetText("输入不正确");
}
function func=new function();
isren=funcren(year);
iscontinue=false;
iscontinue=funcconti(month,day,isren);
if(iscontinue)
{
String str=funcminus(year,month,day,time);
answertextfieldsetText(str);
}
else
{ answertextfieldsetText("输入不正确");
}
}
}
}
class twodates extends Frame implements ActionListener
{
private Button button5,button6;
private TextField yeartextfield1,monthtextfield1,daytextfield1,answertextfield,yeartextfield2,monthtextfield2,daytextfield2;
private Label yearlabel1,monthlabel1,daylabel1,yearlabel2,monthlabel2,daylabel2,answerlabel;
private double year1,month1,day1,year2,month2,day2;
private boolean isren1,isren2,iscontinue;
private int days;
public twodates()
{
super("两个日期计算");
thissetLayout(null);
thissetBounds(0,250,100,800);
thissetSize(800,150);
thissetResizable(false);
button5=new Button("确定");
button6=new Button("清除");
yearlabel1=new Label("请输入第一个年份");
monthlabel1=new Label("请输入第一个月份");
daylabel1=new Label("请输入第一个日期");
yearlabel2=new Label("请输入第二个年份");
monthlabel2=new Label("请输入第二个月份");
daylabel2=new Label("请输入第二个日期");
answerlabel=new Label("答案是");
yeartextfield1=new TextField(5);
monthtextfield1=new TextField(5);
daytextfield1=new TextField(5);
yeartextfield2=new TextField(5);
monthtextfield2=new TextField(5);
daytextfield2=new TextField(5);
answertextfield=new TextField(20);
button5addActionListener(this);
button6addActionListener(this);
yeartextfield1addActionListener(this);
monthtextfield1addActionListener(this);
daytextfield1addActionListener(this);
yeartextfield2addActionListener(this);
monthtextfield2addActionListener(this);
daytextfield2addActionListener(this);
yearlabel1setBounds(0,50,100,20);
yeartextfield1setBounds(100,50,100,20);
monthlabel1setBounds(0,80,100,20);
monthtextfield1setBounds(100,80,100,20);
daylabel1setBounds(0,110,100,20);
daytextfield1setBounds(100,110,100,20);
yearlabel2setBounds(200,50,100,20);
yeartextfield2setBounds(300,50,100,20);
monthlabel2setBounds(200,80,100,20);
monthtextfield2setBounds(300,80,100,20);
daylabel2setBounds(200,110,100,20);
daytextfield2setBounds(300,110,100,20);
button5setBounds(400,80,100,20);
button6setBounds(500,80,100,20);
answerlabelsetBounds(600,80,100,20);
answertextfieldsetBounds(700,80,100,20);
thisadd(yearlabel1);
thisadd(yeartextfield1);
thisadd(monthlabel1);
thisadd(monthtextfield1);
thisadd(daylabel1);
thisadd(daytextfield1);
thisadd(yearlabel2);
thisadd(yeartextfield2);
thisadd(monthlabel2);
thisadd(monthtextfield2);
thisadd(daylabel2);
thisadd(daytextfield2);
thisadd(button5);
thisadd(button6);
thisadd(answerlabel);
thisadd(answertextfield);
thisaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
);
thisshow();
}
public void actionPerformed(ActionEvent e)
{
if (egetSource()==button6)
{
thissetSize(800,150);
yeartextfield1setText("");
monthtextfield1setText("");
daytextfield1setText("");
yeartextfield2setText("");
monthtextfield2setText("");
daytextfield2setText("");
answertextfieldsetText("");
}
else if((egetSource()==button5)||(egetSource()==yeartextfield1)||(egetSource()==monthtextfield1)||(egetSource()==daytextfield1)||(egetSource()==yeartextfield2)||(egetSource()==monthtextfield2)||(egetSource()==daytextfield2))
{
thissetSize(800,150);
try
{
year1=DoubleparseDouble(yeartextfield1getText());
month1=DoubleparseDouble(monthtextfield1getText());
day1=DoubleparseDouble(daytextfield1getText());
year2=DoubleparseDouble(yeartextfield2getText());
month2=DoubleparseDouble(monthtextfield2getText());
day2=DoubleparseDouble(daytextfield2getText());
}
catch (Exception exc)
{
iscontinue=false;
answertextfieldsetText("输入不正确");
}
function func=new function();
isren1=funcren(year1);
isren2=funcren(year2);
iscontinue=false;
iscontinue=(funcconti(month1,day1,isren1))&&(funcconti(month2,day2,isren2));
if(iscontinue)
{
days=funcbetween(year1,month1,day1,year2,month2,day2);
answertextfieldsetText("差"+days+"天");
}
else
{ answertextfieldsetText("输入不正确");
}
}
}
}
class function
{
private String str;
private int year1,month1,day1,time1;
private int days=0;
private double temp;
public boolean ren(double year)
{
if(((year%4==0)&&(year%100!=0))||(year%400==0))
return true;
else return false;
}
public boolean conti(double month,double day,boolean isren)
{
boolean boo=true;
if((month<=0)||(month>12))
{ boo=false;}
else
{
switch ((int)month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: if ((day>31)||(day<=0)) boo=false;
else boo=true;
break;
case 4:
case 6:
case 9:
case 11: if ((day>30)||(day<=0)) boo=false;
else boo=true;
break;
case 2: if (isren)
{
if ((day>29)||(day<=0)) boo=false;
else boo=true;
}
else
{
if ((day>28)||(day<=0)) boo=false;
else boo=true;
}
break;
}
}
return boo;
}
public String plus(double year,double month,double day,double time)
{
year1=(int)year;
month1=(int)month;
day1=(int)day;
time1=(int)time;
for (int i=1;i<=time1;i++)
{
if ((month1==12)&&(day1==31))
{
year1++;
month1=1;
day1=1;
}
else if (((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10))&&(day1==31))
{
month1++;
day1=1;
}
else if(((month1==4)||(month1==6)||(month1==9)||(month1==11))&&(day1==30))
{
//ClockAnimationjava
package p1;
import javaxswing;
import javaawt;
import javaawtevent;
public class ClockAnimation extends JFrame
{
private StillClock clock=new StillClock();
public ClockAnimation()
{
add(clock);
Timer timer=new Timer(1000,new TimerListener());
timerstart();
}
private class TimerListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
clocksetCurrentTime();
clockrepaint();
}
}
public static void main(String[] args)
{
JFrame frame=new ClockAnimation();
framesetTitle("DisplayClock");
framesetSize(400,400);
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
framesetLocationRelativeTo(null);
framesetVisible(true);
}
}
//StillClockjava
package p1;
import javautil;
import javaxswing;
import javaawt;
public class StillClock extends JPanel
{
private int hour;
private int minute;
private int second;
public StillClock()
{
setCurrentTime();
}
public StillClock(int hour,int minute,int second)
{
thishour=hour;
thisminute=minute;
thissecond=second;
}
public int getHour()
{
return hour;
}
public void setHour(int hour)
{
thishour=hour;
repaint();
}
public int getMinute()
{
return minute;
}
public void setMinute(int minute)
{
thisminute=minute;
repaint();
}
public int getSecond()
{
return second;
}
public void setSecond(int second)
{
thissecond=second;
repaint();
}
protected void paintComponent(Graphics g)
{
superpaintComponent(g);
int clockRadius=(int)(Mathmin(getWidth(), getHeight())03);
int xCenter=getWidth()/2;
int yCenter=getHeight()/2;
gsetColor(Colorblack);
gdrawRect(20, 20, getWidth()-70,getHeight()-70);
gsetColor(ColorBLACK);
gdrawOval(xCenter-clockRadius, yCenter-clockRadius, 2clockRadius,2clockRadius);
gdrawString("12", xCenter-5, yCenter-clockRadius+12);
gdrawString("9", xCenter-clockRadius+3, yCenter+5);
gdrawString("3", xCenter+clockRadius-10,yCenter+3);
gdrawString("6", xCenter-3, yCenter+clockRadius-3);
int sLength=(int)(clockRadius08);
int xSecond=(int)(xCenter+sLengthMathsin(second(2MathPI/60)));
int ySecond=(int)(yCenter-sLengthMathcos(second(2MathPI/60)));
gsetColor(Colorred);
gdrawLine(xCenter, yCenter, xSecond, ySecond);
int mLength=(int)(clockRadius065);
int xMinute=(int)(xCenter+mLengthMathsin(minute(2MathPI/60)));
int yMinute=(int)(yCenter-mLengthMathcos(minute(2MathPI/60)));
gsetColor(Colorblue);
gdrawLine(xCenter, yCenter, xMinute, yMinute);
int hLength=(int)(clockRadius05);
int xHour=(int)(xCenter+hLengthMathsin((hour%12+minute/600)(2MathPI/12)));
int yHour=(int)(yCenter-hLengthMathcos((hour%12+minute/600)(2MathPI/12)));
gsetColor(Colorgreen);
gdrawLine(xCenter, yCenter, xHour, yHour);
gsetColor(Colorblack);
gdrawRect(20, getHeight()-35, getWidth()-70,30);
gdrawString("Hour", 60, getHeight()-15);
gsetColor(Colorwhite);
gfillRect(90, getHeight()-25, 30,15);
gsetColor(Colorblack);
gdrawString(""+hour, 95,getHeight()-15 );
gdrawString("Minute", 135, getHeight()-15);
gsetColor(Colorwhite);
gfillRect(180, getHeight()-25, 30,15);
gsetColor(Colorblack);
gdrawString(""+minute, 190,getHeight()-15 );
gdrawString("Second", 230, getHeight()-15);
gsetColor(Colorwhite);
gfillRect(280, getHeight()-25, 30,15);
gsetColor(Colorblack);
gdrawString(""+second, 290,getHeight()-15 );
}
public void setCurrentTime()
{
Calendar calendar=new GregorianCalendar();
thishour=calendarget(CalendarHOUR_OF_DAY);
thisminute=calendarget(CalendarMINUTE);
thissecond=calendarget(CalendarSECOND);
}
public Dimension getPreferredSize()
{
return new Dimension(200,200);
}
}//这是我前段时间写的一个时钟动态显示的程序!不懂的地方就直接追问吧!
package com;
public interface PlaneGraphics {
public abstract double area();
public abstract double perimeter();
public abstract void print();
}
package com;
public class Rectangle implements PlaneGraphics{
private double x = 75;
private double y = 157;
private double s = 0;
private double l= 0;
public double area() {
s = x y;
return s;
}
public double perimeter() {
l = 2 (x + y);
return l;
}
public void print() {
Systemoutprintln("这是长方形");
Systemoutprintln("长方形的宽度:"+x+"长方形的长度:"+y);
Systemoutprintln("长方形的面积:"+s);
Systemoutprintln("长方形的周长:"+l);
}
package com;
public class Ellipse implements PlaneGraphics {
private double a = 57;
private double b = 25;
private double s = 0;
private double l = 0;
private double pie = 314;
public double area() {
s = pie a b;
return s;
}
public double perimeter() {
double m = 0;
m = javalangMathsqrt(a b);
l = pie (15 (a+b) - m);
return l;
}
public void print() {
Systemoutprintln("这是椭圆形");
Systemoutprintln("椭圆形的a轴长:"+a+"椭圆形的b轴长:"+b);
Systemoutprintln("椭圆形的面积:"+s);
Systemoutprintln("椭圆形的周长:"+l);
}
}
package com;
public class Test {
public static void main(String[] args) {
Rectangle rec = new Rectangle();
recarea();
recperimeter();
recprint();
Ellipse ell = new Ellipse();
ellarea();
ellperimeter();
ellprint();
}
}
欢迎分享,转载请注明来源:浪漫分享网
评论列表(0条)