题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-12-17 06:12:56

[简答题]本题是一个Applet,页面中有10个按钮,名称从“0~9”,用鼠标任意单击其中一个按钮后,通过键盘上的上下左右键可以控制按钮在窗口中移动。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class java2 extends Applet______
Button b[]=new Button[10];
int x,y;
public void init( )
for(int i=0;i<=9;i++)
(b[i]=new Button(""+i);
b[i].addKeyListener(this);
add(b[i]);


public void______
Button button=(Button)e.getSource( );
x=button.getBounds( ).x;
y=button.getBounds( ).y;
if(e.getKeyCode( )==KeyEvent.VK_UP)
y=y-2;
if(y<=0)y=0;
button.setLocation(x,y);

else if(e.getKeyCode( )==KeyEvent.VK_DOWN)
y=y+2;
if(y>=300)y=300;
button.setLocation(x,y);

else if(e.getKeyCode( )==KeyEvent.VK_LEFT)
x=x-2;
if(x<=0)x=0;
button.setLocation(x,y);

else if(e.getKeyCode( )==KeyEvent.VK_RIGHT)
x=x+2;
if(x>=300)x=300;
button.setLocation(x,y);


public void keyTyped(

更多"本题是一个Applet,页面中有10个按钮,名称从“0~9”,用鼠标任"的相关试题:

[填空题]本题是一个Applet,页面中有10个按钮,名称从“O~9”,用鼠标任意单击其中一个按钮后,通过键盘上的上下左右键可以控制按钮在窗口中移动。
import java. applet. * ;
import java. awt. * ;
import java. awt. event. * ;
public class java2 extends Applet______
Button b[]=new Button[lO];
int x, y;
public void init( )
for(int i=0; i<=9; i++)
b[i]=new Button(""+i);
b[i]. addKeyListener(this);
add(b[i]);


public void______
Button button=(Button)e. getSource( );
x=button, getBounds( ), x;
y=button, getBounds( ), y;
if(e. getKeyCode( )==KeyEvent. VK_UP)
y=y-2;
if(y<=0) y=0;
button, setgocation(x, y);

else if(e. getKeyCode( )==KeyEvent. VK_DOWN)
y=y+2;
if(y>=300) y=300;
button. setLocation(x, y);

else if (e. getKeyCode( )==KeyEvent. VK_LEFT)
x=x-2;
if(x<=0) x=0;
button. setLocation(x, y);

else if(e. getKeyCode( )==KeyEvent. VK_RIGHT)
x=x+2;
if(x>=300) x=300;
button. setLocation(x, y)
[简答题]本题是一个Applet,功能是用鼠标画不同颜色的图形。页面中有5个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在而板中拖动,就能画出对应颜色的线条,单击“橡皮”按钮,按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class java3 extends Applet implements ActionListener
int x=-1,y=-1,rubberNote=0,clearNote=0;
Color c=new Color(255,0,0);
int con=3;
Button b_red,b_blue,b_green,b_clear,b_quit;
public void init( )

addMouseMotionListener(this);
b_red=new Button("画红色图形");
b_blue=new Button("画蓝色图形");
b_green=new Button("画绿色图形");
b_quit=new Button("橡皮");
b_clear=new Button("清除");
add(b_red);
add(b_green);
add(b_blue);
add(b_quit);
add(b_clear);
b_red.addActionListener(this);
b_green.addActionListener(this);
b_blue.addActionListener(this);
b_quit.addActionListener(this);
b_clear.addActionListener(this);

public void pain
[填空题]本题的功能是定义图形按钮。窗口中有两个图形按钮,当鼠标移上去时,图形按钮的图形将改变,用鼠标单击按钮时图形按钮的图形又发生改变,当鼠标左键松开或者移开鼠标后,图形按钮的图形又恢复原样。
import javax. swing. * ;
import java. awt. * ;
public class java3 extend JButton
public java3(Icon icon, Icon pressed, Icon rollover)
this(icon);
setFocusPainted (alse);
setRolloverEnabled (true);
setRolloverIcon(rollover);
setPressedIcon(pressed);
setBorderPainted (false);
setContentAreaFilled (false);

public static void main(String[] args)
java3 b1=new java3(
new Imagelcon("java3-redcube. gif"),
new ImageIcon("java3-redpaw. gif"),
new Imagelcon("java3-reddiamond. gif"));
java3 b2=new java3(
new ImageIcon("java3-bluecube. gif"),
new Imagelcon("java3-bluepaw. gif"),
new Imagelcon("java3-bluediamond. gif"));
JFrame f=new JFrame( );
f. setTitle("java3");
f. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
c=f. getContentpane( );
c. setLayout(new F
[简答题]本题程序是一个Applet应用程序,功能是更改显示的图片。页面中有一个按钮“改变图形”,单击该按钮,面板中显示的图片改变;继续单击,图片继续改变。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class advance extends Applet implements ActionListener

int n = 0;
Image im1,im2,showim;
Button bn = new Button("改变图形");
public void init( )

add (bn);
______;
im1 = getImage(getCodeBase( ),"advance_1.jpg");
im2 = getImage(getCodeBase( ),"advance_2.jpg");
bn.addActionListener ( this );
showim = im2;

public void actionPerformed(ActionEvent e)

______;
if (e.getActionCommand ( )== "改变" )

if(n%2 == 0)

showim = im1;
n++;

else

showim = im2;
n++;

______;


public void paint (Graphics g)

g.drawImage (showim,0,0,this);

[简答题]本题是一个Applet,功能是监听用对于文本域中文本的选择。页面中有一个文本域、一个“复制”按钮和一个文本框,选中文本域中部分文字后,单击按钮“复制”,所选文字将显示在文本框中。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class java3 extends Applet implements ActionListener

TextArea ta=new TextArea(5,30);
TextField tf=new TextField(30);
Button button=new Button("复制");
String text="AWT提供基本的GUI组件,/n"+"具有可以扩展的超类,/n"+"它们的属性是继承的。/n";
public void init( )

setLayout(new FlowLayout(FlowLayout.left));
ta.setText(text);
ta.setEditable(true);
add(ta);
add(button);
add(tf);
ta.addActionListener(this);

public void actionPerformed(ActionEvent e)

String s;
s=ta.getSelectText( );
if(e.getSource( )==button)
tf.setText(s)s=ta.getSelectText( )


[简答题]本题的功能是定义自已的组件类。窗口中排布着12个按钮,鼠标移动按钮时,按钮背景颜色改变,用鼠标单击按钮时,后台将显示该按钮对应的字符。   import java.awt.*;   import java.awt.event.*;   import java.util.*;   class java3 extends Frame{   String keys="l23456789*0#";   java3( ){   super("java3");   addWindowListener(new WindowAdapter( ){   public void windowClosing(WindowEvent e){   System.exit(O);   }   });   setLayout(new GridLayout(4,3,6,6));   for(int i=0;i  KeyButton kb=new KeyButton(keys.charAt   (i));   kb.addkeyListener(this);   kb.setBackground(Color.pink);   kb.setForeground(Color.black);   add(kb);   }   setSize(200,200);   show( );   }   class KeyEventHandler extends KeyAdapter{   public void keyTyPed(KeyEvent evt){   System.out.println(evt.getChar( ));   }   }   public static void main(String[]args){   newjava3( );   }   }   class KeyButton extends Component{
[简答题]本题是一个Applet,页面上有一个按钮“请单击”,单击该按钮后弹出一个对话框,对话框上有三个按钮“橙色”、“蓝色”和“红色”,单击其中任意一个按钮,则可以将对话框的背景色设置为按钮名称所对应的颜色。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class java2 extends JApplet

private JFrame frame;
______( )

frame=new JFrame( );
frame.setTitle("java2");
frame.setSize(300,200);
frame.getContentPane( ).add(new ButtonPanel( ));
JButton PopButton=new JButton("请单击");
getContentPane( ).add(PopButton);
PopButton.addActionListener(new ActionListener( )

public void actionPerformed(ActionEvent evt)

if(frame.isVisible( ))frame.setVisible(false);
else______;

);


class ButtonPanel extends JPanel

private class ColorAction implements ActionListener

private Color backgroundColor;
public void actionPerformed(ActionEvent actionevent)

setBackground(backgrOundColor);
repaint( );

public ColorAction(
[简答题]下面是一个Applet程序,程序的功能是用鼠标画图。本题是通过单击鼠标后画出一个Java字。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意;不改动程序的结构,不得增行或减行。
源程序文件代码清单如下;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code=SimpleHitMouse.java width=800 height=400>
</applet>
*/
public class SimpleHitMouse implements Applet

private java.util.Vector points=new java.util.Vector( );
public void init( )

addMouseListener(new MouseAdapter( )

public void mousePressed(MouseEvent e)

points.add(new Point(e.getX( ),e.getY( ))
paint( );

);

public void update(Graphics g)

repaint(g);

public void paint(Graphics g)

for(int i=0;i<points.size( );i++)

Point dot=(Point)points.elementAt(i);
g.drawString("x",dot.x,dot.y);


public static void main(String args[ ])

[简答题]下面是一个Applet程序,程序的功能是用鼠标点击画图。本题是通过点击鼠标后画出一个“Java”字。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或减行。
import java. awt.*
import java. awt. event.*;
import java. applet.*
/*
<applet code= SimpleHitMouse. java width= 800 height= 400>
</applet>
*/
public class SimpleHitMouse implements Applet
private java. util. Vector points= new java. util. Vector( );
public void init( )
addMouseListener(new MouseAdapter ( )
public void mousePressed(MouseEvent e) (
points, add (new Point (e. getX( ), e. getY ( ) ) );
paint( );

);

public void update(Graphics g)
repaint(g);

public void paint(Graphics g)
for(int i=0;i<points, size( ) ;i++)
Point dot= (Point)points. elementAt(i);
g. drawString("x" ,dot. x,dot, y),


public static void main(String args[])
Frame fram=new Frame("CelayTree");
[填空题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“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
[简答题]本题程序的功能是:主窗口中有一个按钮,按钮的长和宽每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)



[简答题]本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的面板“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
[单项选择]用鼠标左键单击一个窗口的最小化按钮之后,将使该窗口缩小成为位于( )上的一个按钮。
A. 状态栏
B. 任务栏
C. 工具栏
D. 菜单栏
[简答题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。   import java.awt.*;   import java.awt.event.*;   import javax.swing.*;   class PlafPanel extends JPanel implements ActionLis-   tener   {public ( )   {metaIButton=new JButton("Metal");   motifButtOn=new J Button("Motif");   windowsButton=new JButton("Windows");   add(metalButton);   add(motifButton);   add(windowsButton);   metalButton.addActionListener(this);   motifButton.addActionListener(this);   windowsButton.addActionListener(this);   }   Dublic void actionPerformed(ActionEvent evt)   {Object source=evt.getSource( );   String plaf="":   if(source= =metalButton)   plaf="javax.swing.plaf.metal.MetalLookAnd-   Feel";   else if(source= =motifButton)   plaf="com.sun.java.swing.plaf.motif.Moti-   fLookAndFeel";   else if(source= =windowsButton

我来回答:

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

订单号:

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