题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-10-15 19:10:20

[简答题]本题的功能是用文本框来设定表盘中指针的位置。窗口中有一个画板和两个文本框,画板中绘制了一个表盘和时针、分针,通过文本框分别设定“时”和“分”,表盘中的时针和分针就会指到对应的位置上。
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.setDefauhCloseOperation(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 DocurnentListener( );
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.getDocument( ).addDocumentListener(liste

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

[简答题]本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为“鼠标的当前位置: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. 编辑栏
[简答题]本题的功能是监听鼠标左右键的单击,以及面板中滚动条的添加。在窗口的画板中单击鼠标左键,在单击的位置绘制一个圆,当绘制的圆大于画板的大小时,画板就添加滚动条,在画板中单击鼠标右键,则清除画板中的所有图形。
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
[简答题]本题的功能是跟踪鼠标在窗口的操作,以及在窗口的坐标,包括移进、移出、移动、单击、释放和拖曳,并将这些信息显示在窗口的文字标签上。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class java3 extends JFrame implements MouseListener MouseMotionListener

private JLabel statusBar;
public java3( )

super("java3");
statusBar=new JLabel( );
getContentPane.add(statusBar,BorderLayout.SOUTH);
addMouseListener(this);
addMouseMotionListener(this);
setSize(275,100);
show( );

public void mouseClicked(MouseEvent e)

statusBar.setText("Clicked at["+e.getX( )+","+e.getY( )+"]");

public void mousePressed(MouseEvent e)

statusBar.setText("Pressed at["+e.getX( )+","+e.getY( )+"]");

public void mouseReleased(MouseEvent e)

statusBar.setText("Released at["+e.getX( )+","+e.getY( )+"]");

public void mouseIn(MouseEvent e)

statusBar.setText("Mouse in window");

public vo
[填空题]本题的功能是监听键盘键的敲击,并显示在窗口中。
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
[判断题]当鼠标指针移到窗口边线上时,指针将变为钭向双向箭头。
[简答题]本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的面板“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(title Text);
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.CENTER);
middle
[填空题]本题是一个Applet,它的功能是在窗口上添加12×12个标签,并且横向和纵向标签的颜色为黑白相间。
import java. applet. * ;
import java. awt. * ;
import java. awt. event. * ;
public class java2
extends Applet
GridLayout grid;
public void init( )
grid=new GridLayout(12,12);
setLayout(grid);
Label______=new Label[12][12];
for(int i=0; i<12; i++)
for(intj=0; j<12; j++)
label[i][j]=______;
if((i+j)%2==0)
label[i][j]. setBackground(Color. black);
else
label[i][j]. setBackground(Color. white);
add(labelEi][j]);




[填空题]本题的功能是获得系统剪贴板中的内容。窗口中有一个菜单“Edit”和一个文本域,“Edit”中有菜单项“Cut”、“Copy”和“Paste”,在文本域中输入内容,可以通过菜单进行剪切、复制和粘贴操作,如果系统剪贴板为空,又做粘贴操作的话,则设置文本域中背景颜色为红色,并显示错误信息。
import java. awt. * ;
import java. io. * ;
import java. awt. datatransfer. * ;
import java. awt. event. * ;
class java3 extends Frame implements ActionListener,
ClipboardOwner
TextArea textArea=new TextArea( );
java3( )
super("java3");
addWindowListener(new WindowAdapter( )
public void windowClosing(WindowEvent e)
System. exit(0);
/);
MenuBar mb=new MenuBar( );
Menu m=new Menu("Edit");
setLayout(new BorderLayout( ));
add("Center", textArea);
m. add("Cut");
m. add("Copy");
m. add("Paste");
mb. add(m);
setMenuBar(this);
for (int i=0; i<m. getItemCount( ); i++)
m. item(i). addActionListener(this);
setSize(300,300);
show( );

public void actionPerformed(ActionEvent evt)
if ("Paste". equals(ev
[简答题]本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class java3

public static void main(String[]args)

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


class TransformTest extends JFrame

public TransformTestFrame( )

setTitle("java3");
setSize(WIDTH,HEIGHT);
Container contentPane=getContentPane( );
canvas=new TransformPanel( );
contentPane.add(canvas,BorderLayout,CENTER);
JPanel buttonPanel=new JPanel( );
ButtonGroup group=new ButtonGroup( );
JRadioButton rotateButton
=new JRadioButton("旋转",true);
buttonPanel.add(rotateButton);
group.add(rotateButton);
rotateButton.addActionListener(new
ActionListener( )
[简答题]本题的功能是通过鼠标确定两个点,然后画两点间的直线。窗口中有一个按钮“Draw line”,单击该按钮后,它就处于按下状态,然后用鼠标在窗口中单击一下,在单击的地方就会出现一个坐标圆点,用鼠标在另外一个地方单击一下又会出现另外一个圆点,并且此时在两个坐标圆点间画出一条直线,且“Draw line”处于可用状态,再单击这个按钮就可以画另外一条直线。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class EventQueuePanel extends JPanel implements ActionListener
EventQueuePanel( )
JButton button=new JButton("Draw line");
add(button);
button.addActionListener(this);

public void actionPerformed(AclionEvent evt)
Graphics g=getGraphics( );
______p=getClick( );
g.drawOval(p.x-2,p.y-2,4,4);
Point q=getClick( );
g.drawOval(q.x-2,q.y-2,4,4);
g.drawLine(p.x,p.y,q.x,q.y);
g.dispose( );

public Point getClick( )
EventQueue eq=Toolkit.getDefaultToolkit( ).getSystemEventQueue( );
while(true)
try
AWTEvent evt=eq.getNextEvent( );
if(evt.getID( )==MouseEvent.MOUSE PRESSED)
MouseEvent mevt=(MouseEvent)evt;
Point p=______( );
Poi

我来回答:

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

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码