Java语言程序设计模拟题8Word格式文档下载.docx
- 文档编号:21477766
- 上传时间:2023-01-30
- 格式:DOCX
- 页数:10
- 大小:36.09KB
Java语言程序设计模拟题8Word格式文档下载.docx
《Java语言程序设计模拟题8Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Java语言程序设计模拟题8Word格式文档下载.docx(10页珍藏版)》请在冰豆网上搜索。
二、程序解释题(共1题,共20分)
importjava.awt.*;
importjava.awt.event.*;
publicclassMouseeventextendsWindowAdapterimplementsMouseMotionListener{
Framef=newFrame();
Panelp1=newPanel();
Panelp2=newPanel();
Labell1=newLabel("
X轴"
);
Labell2=newLabel("
Y轴"
TextFieldtf1=newTextField(4);
TextFieldtf2=newTextField(4);
intx;
inty;
publicstaticvoidmain(String[]asgs){
Mouseeventhua=newMouseevent();
hua.go();
}
privatevoidgo(){
f.setSize(300,200);
f.add(p2,"
South"
p2.add(l1);
p2.add(tf1);
p2.add(l2);
p2.add(tf2);
f.add(p1);
p1.addMouseMotionListener(this);
f.addWindowListener(this);
f.setVisible(true);
publicvoidmouseDragged(MouseEventevent){
publicvoidmouseMoved(MouseEventevent){
tf1.setText(Integer.toString(event.getX()));
tf2.setText(Integer.toString(event.getY()));
publicvoidwindowClosing(WindowEventwe){
System.exit(0);
参考答案:
1、classSa{
publicstaticvoidmain(String[]args){
if(args[0].equals(“Good”)){
System.out.println(“好”);
}
if(args[0].equals(“Bad”)){
System.out.println(“坏”);
2、classSa{
publicSa(Stringx){
if(x.equals(“Good”)){
if(x.equals(“Bad”)){
publicclassSb{
Sasa=newSa(args[0]);
3、在Sb类的定义前加上语句importmypackage.jiafa;
即可。
4、classDays{
staticintdayInmonth(inta){
ints=31;
switch(a)
{case2:
s=28;
break;
case4:
case6:
case9:
case11:
s=30;
returns;
inta=Integer.parseInt(args[0]);
intb=dayInmonth(a);
System.out.println(a+"
月有"
+b+"
天"
5、classCla{
staticvoidconvert(Strings){
try{
doublea=Double.parseDouble(s);
System.out.println(a);
}catch(NumberFormatExceptione){
System.out.println("
所输入的字符串中含有非数字的文字,无法转换"
convert(args[0]);
6、importjava.awt.*;
classMyframeimplementsActionListener{
Framef=newFrame("
窗口更改大小"
Panelp=newPanel();
Panelp1=newPanel();
Labell=newLabel("
宽:
"
Labell1=newLabel("
高:
TextFieldtf=newTextField(4);
TextFieldtf1=newTextField(4);
Buttonb=newButton("
更改"
Buttonb1=newButton("
退出"
Myframemy=newMyframe();
my.go();
voidgo(){
p.add(l);
p.add(tf);
p.add(l1);
p.add(tf1);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p,"
North"
f.setSize(200,100);
publicvoidactionPerformed(ActionEvente){
Strings=e.getActionCommand();
if(s.equals("
)){
inta=Integer.parseInt(tf.getText());
intb=Integer.parseInt(tf1.getText());
//f.setSize(a,b);
f.resize(a,b);
elseSystem.exit(0);
7、importjava.awt.*;
importjavax.swing.*;
publicclassMyappletextendsJApplet{
JRadioButtonjRadioButton1=newJRadioButton("
RadioButton1"
JRadioButtonjRadioButton2=newJRadioButton("
RadioButton2"
ButtonGroupbtg=newButtonGroup();
JCheckBoxjCheckBox1=newJCheckBox("
CheckBox1"
JCheckBoxjCheckBox2=newJCheckBox("
CheckBox2"
JCheckBoxjCheckBox3=newJCheckBox("
CheckBox3"
JTextFieldjTextField1=newJTextField("
TextField1"
JLabeljLabel1=newJLabel("
Label1"
FlowLayoutflowLayout1=newFlowLayout();
publicvoidinit(){
myInit();
voidmyInit(){
this.getContentPane().setLayout(flowLayout1);
btg.add(jRadioButton1);
btg.add(jRadioButton2);
this.getContentPane().add(jRadioButton2,null);
this.getContentPane().add(jRadioButton1,null);
this.getContentPane().add(jCheckBox1,null);
this.getContentPane().add(jCheckBox2,null);
this.getContentPane().add(jCheckBox3,null);
this.getContentPane().add(jLabel1,null);
this.getContentPane().add(jTextField1,null);
<
appletcode=Myapplet.classwidth=400height=400>
/applet>
8、importjava.awt.*;
classjisuanqiimplementsActionListener{
计算器"
Panelp2=newPanel();
x+y"
x-y"
Buttonb2=newButton("
清除"
Labellbx=newLabel("
x"
Labellby=newLabel("
y"
TextFieldtfx=newTextField(4);
TextFieldtfy=newTextField(4);
TextAreata=newTextArea();
Fontft=newFont("
宋体"
Font.BOLD,18);
GridLayoutg1=newGridLayout(4,1);
GridLayoutg2=newGridLayout(2,1);
doublex,y,sum;
jisuanqiji=newjisuanqi();
ji.go();
publicvoidgo(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
lbx.setAlignment(Label.CENTER);
lby.setAlignment(Label.CENTER);
lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
West"
p1.setLayout(g2);
f.add(p1,"
East"
p2.add(b2);
b2.addActionListener(this);
f.add(ta,"
Center"
f.setSize(250,150);
publicvoidactionPerformed(ActionEventae){
Strings=ae.getActionCommand();
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
)==true){
ta.append("
x+y="
+(x+y)+"
\n"
x-y="
+(x-y)+"
ta.setText("
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 语言程序设计 模拟