JAVA图形界面编程建立一个窗口,界面运行效果当单击四个按钮时分别在上面的文本框中显示当前的选项!
程序最后要出现一个窗口,窗口的名字叫做“显示时间”,窗口上有“年份”、“月份”、“星期”、“日期”四个按钮(按钮分成两行),当单击“年份”、“月份”、“星期”、“日期”按...
程序最后要出现一个窗口,窗口的名字叫做“显示时间”,窗口上有“年份”、“月份”、“星期”、“日期”四个按钮(按钮分成两行),当单击“年份”、“月份”、“星期”、“日期”按钮时分别在上面的文本框中显示当前的年份、日期、星期和日期。谢谢各位高手帮我编个java程序!
展开
4个回答
展开全部
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import java.util.Date;
public class Form1 extends Form
{
Date today=new Date();
String []day={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
public Form1()
{
// Required for Visual J++ Form Designer support
initForm();
// TODO: Add any constructor code after initForm call
}
public void dispose()
{
super.dispose();
components.dispose();
}
private void button1_click(Object source, Event e)
{
edit1.setText(String.valueOf(today.getYear()+1900)+"年");
}
private void button2_click(Object source, Event e)
{
edit2.setText(String.valueOf(today.getMonth()+1)+"月");
}
private void button3_click(Object source, Event e)
{
edit3.setText(day[today.getDay()]);
}
private void button4_click(Object source, Event e)
{
edit4.setText(String.valueOf(today.getDate())+"日");
}
Container components = new Container();
Edit edit1 = new Edit();
Edit edit2 = new Edit();
Edit edit3 = new Edit();
Edit edit4 = new Edit();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
private void initForm()
{
this.setText("显示时间");
this.setAutoScaleBaseSize(new Point(6, 12));
this.setClientSize(new Point(463, 158));
this.setStartPosition(FormStartPosition.CENTER_SCREEN);
edit1.setLocation(new Point(40, 48));
edit1.setSize(new Point(88, 19));
edit1.setTabIndex(3);
edit1.setText("");
edit2.setLocation(new Point(136, 48));
edit2.setSize(new Point(88, 19));
edit2.setTabIndex(2);
edit2.setText("");
edit3.setLocation(new Point(232, 48));
edit3.setSize(new Point(88, 19));
edit3.setTabIndex(1);
edit3.setText("");
edit4.setLocation(new Point(328, 48));
edit4.setSize(new Point(88, 19));
edit4.setTabIndex(0);
edit4.setText("");
button1.setLocation(new Point(40, 80));
button1.setSize(new Point(88, 24));
button1.setTabIndex(7);
button1.setText("年份");
button1.addOnClick(new EventHandler(this.button1_click));
button2.setLocation(new Point(136, 80));
button2.setSize(new Point(88, 24));
button2.setTabIndex(6);
button2.setText("月份");
button2.addOnClick(new EventHandler(this.button2_click));
button3.setLocation(new Point(232, 80));
button3.setSize(new Point(88, 24));
button3.setTabIndex(5);
button3.setText("星期");
button3.addOnClick(new EventHandler(this.button3_click));
button4.setLocation(new Point(328, 80));
button4.setSize(new Point(88, 24));
button4.setTabIndex(4);
button4.setText("日期");
button4.addOnClick(new EventHandler(this.button4_click));
this.setNewControls(new Control[] {
button4,
button3,
button2,
button1,
edit4,
edit3,
edit2,
edit1});
}
public static void main(String args[])
{
Application.run(new Form1());
}
}
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import java.util.Date;
public class Form1 extends Form
{
Date today=new Date();
String []day={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
public Form1()
{
// Required for Visual J++ Form Designer support
initForm();
// TODO: Add any constructor code after initForm call
}
public void dispose()
{
super.dispose();
components.dispose();
}
private void button1_click(Object source, Event e)
{
edit1.setText(String.valueOf(today.getYear()+1900)+"年");
}
private void button2_click(Object source, Event e)
{
edit2.setText(String.valueOf(today.getMonth()+1)+"月");
}
private void button3_click(Object source, Event e)
{
edit3.setText(day[today.getDay()]);
}
private void button4_click(Object source, Event e)
{
edit4.setText(String.valueOf(today.getDate())+"日");
}
Container components = new Container();
Edit edit1 = new Edit();
Edit edit2 = new Edit();
Edit edit3 = new Edit();
Edit edit4 = new Edit();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
private void initForm()
{
this.setText("显示时间");
this.setAutoScaleBaseSize(new Point(6, 12));
this.setClientSize(new Point(463, 158));
this.setStartPosition(FormStartPosition.CENTER_SCREEN);
edit1.setLocation(new Point(40, 48));
edit1.setSize(new Point(88, 19));
edit1.setTabIndex(3);
edit1.setText("");
edit2.setLocation(new Point(136, 48));
edit2.setSize(new Point(88, 19));
edit2.setTabIndex(2);
edit2.setText("");
edit3.setLocation(new Point(232, 48));
edit3.setSize(new Point(88, 19));
edit3.setTabIndex(1);
edit3.setText("");
edit4.setLocation(new Point(328, 48));
edit4.setSize(new Point(88, 19));
edit4.setTabIndex(0);
edit4.setText("");
button1.setLocation(new Point(40, 80));
button1.setSize(new Point(88, 24));
button1.setTabIndex(7);
button1.setText("年份");
button1.addOnClick(new EventHandler(this.button1_click));
button2.setLocation(new Point(136, 80));
button2.setSize(new Point(88, 24));
button2.setTabIndex(6);
button2.setText("月份");
button2.addOnClick(new EventHandler(this.button2_click));
button3.setLocation(new Point(232, 80));
button3.setSize(new Point(88, 24));
button3.setTabIndex(5);
button3.setText("星期");
button3.addOnClick(new EventHandler(this.button3_click));
button4.setLocation(new Point(328, 80));
button4.setSize(new Point(88, 24));
button4.setTabIndex(4);
button4.setText("日期");
button4.addOnClick(new EventHandler(this.button4_click));
this.setNewControls(new Control[] {
button4,
button3,
button2,
button1,
edit4,
edit3,
edit2,
edit1});
}
public static void main(String args[])
{
Application.run(new Form1());
}
}
展开全部
调用一下时间函数DataTime
再用控件赋值,
虽然我没有接触过JAVA,但我觉得应该也差不多!
我学的 C charp ,JAVA如果不是个人特别喜好,就别学了!
学C#吧!
再用控件赋值,
虽然我没有接触过JAVA,但我觉得应该也差不多!
我学的 C charp ,JAVA如果不是个人特别喜好,就别学了!
学C#吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单~java图形界面完全没有市场的,学这个干嘛~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
10fen ?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询