题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-10-18 13:02:58

[填空题]本题的功能是用文本框来设定表盘中指针的位置。窗口中有一个画板和两个文本框,画板中绘制了一个表盘和时针、分针,通过文本框分别设定“时”和“分”,表盘中的时针和分针就会指到对应的位置上。
import java. awt. * ;
import java. awt. event. * ;
import java. awt. geom. * ;
import javax. swing. * ;
import javax. swing, event. * ;
public class java3

public static void main(String[] args)

TextTestFrame frame=new TextTestFrame( );
frame. setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
frame. show( );


class TextTestFrame extends JFrame

public TextTestFrame( )

setTitle("java3");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
Container contentPane=getContentPane( );
DocumentListener listener=new DocumentListen-er( );
JPanel panel=new JPanel( );
hourField=new JTextField("12",3);
panel, add(hourField);
hourField, getDocument ( ). addDocumentListener(this);
minuteField=new JTextField("00",3);
panel, add(minuteField);
minuteField, getDocume

更多"本题的功能是用文本框来设定表盘中指针的位置。窗口中有一个画板和两个文本"的相关试题:

[简答题]本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为“鼠标的当前位置:X:Y”。(其中,X为横坐标,Y为纵坐标)
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class java2

public static void main(string[]args)

MouseFrame frame=new MouseFrame( );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show( );


class MouseFrame extends JFrame

public MouseFrame( )

setTitle("java2");
setSize(WIDTH,HEIGHT);
MousePanel panel=new MousePanel( );
Container contentPane=getContentPane( );
contentPane.add(panel);

public static final int WIDTH=300;
public static final int HEIGHT=200;

class MousePanel extends JPanel

public MousePanel( )

addMouseListener(new MouseHandler( ));
addMouseMotionListener(new MouseMorionHandler( ));

public void paintComponent(Graphics g)

super.paintComponent(g);

[单项选择]将鼠标指针移动到窗口的( )位置上拖曳,可以移动窗口。
A. 工具栏
B. 标题栏
C. 状态栏
D. 编辑栏
[简答题]本题程序的功能是:主窗口中有两个按钮“Start”和“Close”,单击按钮“Start”后会在窗口左上角生成一个黑色实心小球,小球做斜线运动,碰到面板边缘后反弹几次后停止运动,再次单击按钮“Start”后又会生成一个小球做同样的运动。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class advance

public static void main (String[] args)

JFrame frame = new BounceFrame( );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.show( );

class BounceFrame extends JFrame

public BounceFrame( )

setSize(WIDTH,HEIGHT);
setTitle("advance");
Container contentPane = getContentPane( );
Canvas = new BallCanvas( );
contentPane.add(canvas,BorderLayout.CENTER);
JPanel buttonPanel = new JPanel( );
addButton(buttonPanel,"Start",new ActionListener( )
public void actionPerformed(ActionEvent evt)

addBall( );

);
addButton(buttonPanel,"Close",new ActionListener
[简答题]本题的功能是监听鼠标左右键的单击,以及面板中滚动条的添加。在窗口的画板中单击鼠标左键,在单击的位置绘制一个圆,当绘制的圆大于画板的大小时,画板就添加滚动条,在画板中单击鼠标右键,则清除画板中的所有图形。
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class java3 extends JPanel
private Dimension size;
private Vector objects;
private final Color colors[]=
Color.red,Color.blue,Color.green,Color.orange,
Color.cyan,Color.magenta,Color.darkGray,Color.yellow;
private final int color_n=colors.length;
JPanel drawingArea;
public java3( )
setOpaque(true);
size=new Dimension(0,0);
objects=new Vector( );
JLabel instructionsLeft=new JLabel("单击鼠标左键画圆.");
JLabel instructionsRight=new JLabel("单击鼠标右键清空画板.");
JPanel instructionPanel=new JPanel(new GridLayout(0,1));
instructionPanel.add(instructionsLeft);
instructionPanel.add(instructionsRight);
drawingArea=new JPanel( )
protected void paintComponen
[填空题]本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。
import java. awt. * ;
import java. awt. event. * ;
import javax. swing. * ;
class MousePanel extends JPanel extends MouseMotionListener
public MousePanel( )
addMouseListener(new MouseAdapter( )
public void mousePressed(MouseEvent evt)
int x=evt. getX( );
int y=evt. getY( );
current=find(x, y);
if(current<0)
add(x, y);

public void mouseClicked(MouseEvent evt)
int x=evt. getX( );
int y=evt. getY( );
if(evt. getClickCount( )>=2)
remove(current);


);
addMouseMotionListener(this);

public void paintComponent(Graphics g)
(super. paintComponent( );
for (int i=0; i<nsquares; i++)
draw(g, i);

public int find(int x, int y)
for(int i=0; i<nsquares; i++)
if (squares[i]. x-SQUARELENGTH/2<=x&&
x<=squares[i], x+SQUARELENGTH/2
&&squares[i], y-SQUARELENGTH/2<=y
&&y<=s
[简答题]本题程序的功能是使用GridBayLayout来组织窗口上的按钮。窗口中共有7个按钮,前3个按钮放置在第1排,第4个按钮独占第2排,第6个按钮位于第3排的右侧,而第5和第7个按钮共同处于第3排的左侧。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class simple extends Jframe

private JPanel jpanel1=new JPanel( );
private GridLayout g1;
private JButton JButton1 = new JButton("第一个");
private JButton JButton2 = new JButton("第二个");
private JButton JButton3 = new JButton("第三个");
private JButton JButton4 = new JButton("第四个");
private JButton JButton5 = new JButton("第五个");
private JButton JButton6 = new JButton("第六个");
private JButton JButton7 = new JButton("第七个");
public ______( )

super("simple");
setSize(300,150);
GridBagLayout gbl= ______;
jpanell.setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints( );
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.gridx = 0;

[简答题]本题程序的功能是主窗口有一个按钮、一个文本域和一个复选框,初始时窗口的大小是不能调整的,勾选复选框后,窗口大小就可以进行调整,如果取消勾选复选框,则窗口的大小又不能调整,单击按钮可以关闭程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame______

Checkbox box;
TextArea text;
Button button;
MyFrame(String s)

super (s);
box = new Checkbox("设置窗口是否可调整大小");
text = new TextArea(12,12);
button = new Button("关闭窗口");
button.addActionListener(this);
box.addItemListener(this);
setBounds(100,100,200,300);
setVisible(true);
add(text,BorderLayout.CENTER);
add(box,BorderLayout.SOUTH);
add(button,BorderLayout.NORTH);
______;
validate ( );

public void itemStateChanged(ItemEvent e)

if (box.getState( ) == true)

setResizable(true);

else

setResizable(false);


public void actionPerformed(ActionEvent e)

dispose( );


class simple


[填空题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif和“WindoWS“,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。
import java.awt*;
import java.awt.event.*;
import javax.swing.*;
class PlafPanel extends JPanel implements Actionlis-tener
public______( )
metalButton=new JButton("Metal");
motifButton=new JButton("Motif");
windowsButton=new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButlon.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);

public void actionPerformed(ActionEvent evt)
Object source=evt.getSource( );
string plaf="";
if(source==metaIButton)
pIaF="javax.swing.plaf.metal.MetalLookAncl-Feel";
else if(source==motifButton)
plaf="com.sun.java.swing.plaf.motif.Moti-fLookAndFeel";
else if(source==windowsButton)
plaf="com.sun.java.swing.plaf.windows.windowsLookAndFeel";
try
UIManager.setLookAndF
[简答题]本题程序的功能是:单击窗口左上角的File菜单中的Open命令,打开一个GIF图像文件,并将图像文件显示在窗口中;单击File菜单中的Exit命令,能够退出程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
public class simple extends JFrame implements ActionListener

public simple( )

setTitle ("ImageViewer" );
setSize(300,400);
JMenuBar mbar = new JMenuBar( );
JMenu m = new JMenu("File");
openItem = new JMenuItem("Open");
openItem,addActionListener (this);
m.add (openItem);
exitItem = new JMenuItem("Exit");
exitItem.addActionListener(this);
m.add(exitItem);
mbar.add (m);
setJMenuBar (mbar);
label = new JLabel( );
Container contentPane = getContentPane( );
contentPane.add(label,"Center");
public void actionPerformed(ActionEvent evt)
Object source = evt.getSource( );
if (source == openItem)

JFileChooser chooser = new JFileCho
[简答题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PlafPanel extends JPanei implements ActionListener
public______( )
metalButton=new JButton("Metal");
motifButton=new JButton("Motif");
windowsButton=new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);

public void actionPerformed(ActionEvent evt)
Object source=evt.getSource( );
String plaf="";
if(source==metalButton)
plaf="javax.swing.plaf.metal.MetalLookAndFeel";
else if(source==motifButton)
plaf="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if(source==windowsButton)
plaf="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
UIManager.setLookAndFeel
[简答题]本题程序的功能是:主窗口中有一个按钮,按钮的长和宽每200ms增加1,当达到100时又恢复原来大小重新进行增加。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import java.awt.*;
import java.awt.event.*;
public class simple

public static void main (String args[])

Mywin win = new Mywin( );


class Mywin extends Frame ______

Button b = new Button("按钮");int x = 5;
Thread bird = null;
Mywin ( )

setBounds(100,100,400,400); setLayout(new FlowLayout( ));
setTitle ("simple");
setVisible (true);
add(b);
b.setBackground (Color.green);
addWindowListener (new WindowAdapter ( )
public void windowClosing(WindowEvent e)

System.exit (0);

);
bird = new Thread(this);
bird.start( );

public ______

while (true)

x = x+1;
if(x > 100)
x = 5;
b.setBounds(40,40,x,x);
try

bird.sleep (200);

catch(InterruptedException e)



[填空题]本题的功能是监听键盘键的敲击,并显示在窗口中。
import javax. swing. * ;
import java. awt. * ;
import java. awt. event. * ;
public class java3 extends JFrame extends KeyListener

private String line1="", line2="";
private String line3="";
private JTextArea textArea;
public java3( )

super("java3");
textArea=new JTextArea(10,15);
textArea, setText("Press any key on the key-board... ");
textArea, setEnabled(false);
addKeyListener(this);
getContentPane( ). add(textArea);
setSize(350,100);
show( );

public void keyPressed(KeyEvent e)

lind="Key pressed:"+e. getKeyText(e. getKeyCode( ));
setLines2and3(e);

public void keyReleased(KeyEvent e)

line1="Key released:"+e. getKeyText(e. getKeyCode( ));
setLines2and3(e);

public void keyTyped(KeyEvent e)

Lind="Key typed:"+e. getKeychar( );
setLines2and3(e);

private void setLines2and3
[简答题]本题的功能是监听键盘键的敲击,并显示在窗口中。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class java3 extends JFrame extends KeyListener

private String linel="",line2="";
private String line3="";
private JTextArea textArea;
public java3( )

super("java3");
textArea=new JTextArea(10,15);
textArea.setText("Press any key on the keyboard...");
textArea.setEnabled(false);
addKeyListener(this);
getContentPane( ).add(textArea);
setSize(350,100);
show( );

public void keyPressed(KeyEvent e)

line1="Key pressed:"+e.getKeyText(e.getKeyCode( ));
setLines2and3(e);

public void keyReleased(KeyEvent e)

linel="Key released:"+e.getKeyText(e.getKeyCode( ));
setLines2and3(e);

public void keyTyped(KeyEvent e)

Line1="Key typed:"+e.getKeychar( );
setLines2and3(e);

private void setLines2and3(KeyEvent e)
<
[简答题]本题程序的功能是主窗口里有一个文本框和两个按钮“开始”和“关闭”。单击“开始”按钮后该按钮处于按下状态,文本框中的数开始从0计数到49,每间隔50ms增加1,计数完毕后“开始”按钮变为可使用状态,单击“关闭”按钮则退出程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class simple

public static void main (String[] args)

JFrame frame = new CounterFrame( );
frame.setDefaultCloseOperation(JFrame.EXIT ON CLOSE);
frame.show( );


class CounterFrame extends JFrame

public static final int WIDTH = 250;
public static final int HEIGHT = 150;
private TextField textField = new TextField(20);
public CounterFrame( )

setSize(WIDTH,HEIGHT);
setTitle("simple");
Container contentPane = getContentPane( );
JPanel textPanel = new JPanel( );
textPanel.add(textField);
JPanel buttonPanel = new JPanel( );
addButton(buttonPanel,"开始",new ActionListener( )
public void actionPerformed(ActionEvent evt)

addCounter( )
[填空题]本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的面板“Sample text”和“Text color control”,窗口的底部还有一个复选按钮“Disable changes”。在“Sample text”面板中有一个带有字符串的文本框,而在“Text color control”面板中有三个按钮“Black”、“Red”和“Green”,并且每个按钮上都有一个对应颜色的圆。单击任意按钮,文本框的文本变成对应的颜色,如果选中“Disable changes”复选框,则三个颜色按钮变为不可用,如果取消选中复选框,则三个按钮变为可用。
import javax. swing. * ;
import java. awt. * ;
import java. awt. event. * ;
public class java3 extends JFrame
private JPanel upper, middle, lower;
private JTextField text;
private JButton black, red, green;
private JCheckBox disable;
public java3 (String titleText)
super (titleText);
addWindowListener (new WindowAdapter( )
public void
windowClosing (WindowEvent e)
System. exit(0);

);
upper=new JPanel( );
upper. setBorder (BorderFactory. createTitledBorder("Sample text"));
Upper. setlayout(new BorderLayout( ));
text=new JTextField ("Change the color of this text");
upper. add (text, BorderLayout.
[填空题]本题的功能是监听对于菜单项和工具条的操作。窗口中有一个菜单“Color”和一个工具体,菜单“Color”中有菜单项“Yellow”、“Blue”、“Red”和“Exit”,每个菜单项都有对应的图形,单击前三个颜色菜单项,主窗口就变成对应的颜色,单击“Exit”则退出程序。工具条上有4个按钮,分别为三个颜色按钮和一个退出程序的按钮,单击任意一个颜色按钮,主窗口将变成按钮对应的颜色,单击退出程序按钮,则退出程序。
import java. awt. * ;
import java. awt. event. * ;
import java. beans. * ;
import javax. swing. * ;
public class java3

public static void main(String[] args)

ToolBarFrame frame=new ToolBarFrame( );
frame. setDefaultCloseOperation (JFrame. EXIT_ON CLOSE);
frame. show( );


class ToolBarFrame extends JFrame

public ToolBarFrame( )

setTitle("java3");
setSize (DEFAULT_WIDTH, DEFAULT_HEIGHT);
Container contentPane=getContentPane( );
panel=new JPanel( );
contentPane. add(panel, BorderLayout. CENTER);
Action blueAction=new ColorAction("Blue",
new Imagelcon("java3-blue--ball. gif"), Color.BLUE);
Action yellowAction=new ColorAction ("Yellow",
new Imagelcon("jav

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

截图扫码使用小程序[完全免费查看答案]
请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码