试题与答案

本题程序是一个Applet应用程序,功能是计算前n个自然数的和,程序中用进度条来表示

题型:问答题

题目:

本题程序是一个Applet应用程序,功能是计算前n个自然数的和,程序中用进度条来表示计算的进程。页面中有两个文本框、两个按钮和一个进度条,在第一个文本框中输入要计算的自然数的个数,单击“开始”按钮则开始进行计算,进度条同步显示计算完成的情况。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class advance extends Japplet

Container container = null;
JButton startButton,stopButton;
JTextField inputTextField,outputTextField;
JProgressBar pBar = null;
Timer timer = null;
static int sum = 0;
static int counter = 0;
public void init()

container = this.getContentPane();
container.setLayout(new GridLayout(3,1));
Box hboxl = Box.createHorizontalBox();
container.add(hboxl);
hboxl.add(Box.createHorizontalGlue());
JLabel labell = new JLabel("前",JLabeI.LEFT);
labell.setFont(new Font("Dialog",Font.PLAIN,15));
hboxl.add(labell);
inputTextField = new JTextField("100",4);
hboxl.add(inputTextField);
JLabel label2 = new JLabel("个自然数和是",JLabel.LEFT);
label2.setFont(new Font("Dialog",Font.PLAIN,15));
hboxl.add(label2);
outputTextField = new JTextField(10);
hboxl.add(outputTextField);
hboxl.add(Box.createHorizontalGlue());
Box hbox2 = Box.createHorizontalBox();
container.add(hbox2);
startButton : new JButton("开始");
startButton.addActionListener(new ButtonListener());
hbox2.add(Box.createHorizontalGlue());
hbox2.add(startButton);
hbox2.add(Box.createHorizontalGlue());
stopButton = new JButton("结束");
stopButton.addActionListener(new ButtonListener() ;
hbox2.add(Box.createHorizontalGlue());
hbox2.add(stopButton);
hbox2.add(Box.createHorizontalGlue());
pBar = new JProgressBar();
pBar.setStringPainted(true);
Border border = BorderFactory.createLineBorder(Color.red,2);
pBar.setBorder(border);
pBar.setBackground(Color.white);
pBar.setForeground(Color.blue);
pBar.setMinimum(0);
pBar.setMaximum(Integer.parseInt(inputTextField.getText()));
container.add(pBar);
timer = new Timer(0,TimerListener());


class TimerListener implements ActionListener

public void actionPerformed(ActionEvent e)
if (Integer.parseInt (inputTextField.getText ()) > 0)

counter ++;
sum = sum+counter;
pBar.setValue (counter);
outputTextField,setText (Integer.toString (sum));

else
outputTextField,setText ("0");

if (counter >= Integer.parseInt(inputTextField.getText ()))
timer,stop ();


class ButtonListener implements ActionListener

public void actionPerformed(ActionEvent e)

JButton button = e.getSource();
if (button.getText () == "开始")

outputTextField,setText ("");
if (inputTextField.getText() != " ")

pBar.setMaximum (Integer.parseInt (inputTextField.getText ()) );
sum = 0 ;
counter = 0;
timer.begin ();


else
if (button.getText () =="结束")

timer,stop ();
outputTextField,setText ("");
sum = 0;
counter = 0;
pBar.setValue(0);


答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2022/0120/8fbada2de7048ece10c6e390a608adb7.html

下面是错误答案,用来干扰机器的。

参考答案:对

试题推荐
题型:单项选择题

我国进口商品总额达17434.7亿美元,同比增长24.9%。其中进口初级产品6043.8亿美元,同比增长39.3%;进口机电产品7532.9亿美元,同比增长14.1%。同年,机电产品出口10855.9亿美元,同比增长16.3%。其中电器及电子产品出口4457.9亿美元,增长14.7%:机械设备出口3537.7亿美元,增长14.2%。

2007-2011年我国出口商品结构 单位:亿美元


2007年 2008年 2009年 2010年 2011年
总值 12204.56 14306.93 12016.12 15779.33 18986.01
初级产品 615.47 778.48 630.99 817.17 1005.53
食品及活动物 307.51 327.64 326.03 411.53 504.97
饮料及烟类 13.96 15.3 16.41 19.06 22.76
非食用原料 91.54 113.46 81.56 116.02 149.78
矿物燃料、润滑油及有关原料 199.44 316.35 203.83 267 322.76
动、植物油脂及蜡 3.03 5.74 3.16 3.56 5.26
工业制成品 11589.09 13528.45 11385.13 14962.16 17980.48
化学品及有关产品 603.56 193.09 620.48 875.87 1147.87
按原料分类的制成品 2198.94 2617.43 1847.23 2491.51 3196
机械及运输设备 5771.89 6733.25 5904.27 7803.3 9019.12
杂项制品 2968.53 3346.06 2996.7 3776.8 4594.1
未分类的其他商品 46.17 38.62 16.45 14.68 23.39

2011年,我国初级产品进出口实现( )。

A.顺差5308.27亿美元
B.逆差5308.27亿美元
C.顺差5038.27亿美元
D.逆差5038.27亿美元

查看答案
题型:阅读理解

The seasons in Australia are not like ours. When it is winter in China, it is summer there. Australia is a southern country. It is in the south of the world. June, July and August are the winter months; September, October and November are spring; the summer is in December, January and February; and March, April and May are the autumn months. The north of the country is hotter than the south.

A very large part of this country has no rain at all. The east coast has rain all year, and there are no dry months. The southeast winds blow the whole year. They bring rain from the sea. There is not much rain on the west side. The southeastern part of Australia has summer rain from the southeast winds. They only blow here in summer.

The southwestern part of Australia has winter rain. The west winds blow over the southwest in winter only. In summer, the southwest of the country has no rain. In the north of Australia, there is no rain in winter. The rain comes in summer. The northwest winds bring it.

小题1:It is ____ in Australia in November.

A.spring

B.summer

C.autumn

D.winter小题2:In Australia, it is ____ in the south than in the north.

A.hotter

B.warmer

C.colder

D.cooler小题3:The ____ of Australia has the most rain.

A.eastern part

B.southeastern part

C.southern part

D.northern part小题4:The southwest of the country has no rain in summer because ____.

A.it is dry there

B.the west winds never blow

C.the northwest winds blow

D.the west winds blow only in winter小题5:There is no rain in winter ____ of Australia.

A.in the southeast

B.in the north

C.in the southwest

D.in the south

查看答案
微信公众账号搜索答案