题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2024-01-11 07:46:37

[简答题]本题的功能是定义自已的组件类。窗口中排布着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{

更多"本题的功能是定义自已的组件类。窗口中排布着12个按钮,鼠标移动按钮时,"的相关试题:

[填空题]本题的功能是定义图形按钮。窗口中有两个图形按钮,当鼠标移上去时,图形按钮的图形将改变,用鼠标单击按钮时图形按钮的图形又发生改变,当鼠标左键松开或者移开鼠标后,图形按钮的图形又恢复原样。
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
[简答题]本题程序的功能是:主窗口中有两个按钮“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
[简答题]本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes”和“No”,单击对话框上的“Yes”和“No”按钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。
import java.awt.event.*;
import java.awt.*;
class MyDialog______implements ActionListener
static final int YES=1,NO=0;
int message=-1;Button yes,no;
MyDialog(Frame f,String s,boolean b)
super(f,s,b);
yes=new Button("Yes");yes.addActionListener(this);
no=new Button("No");no.addActionListener(this);
setLayout(new FlowLayout( ));
add(yes);add(no);
setBounds(60,60,100,100);
addWindowListener(new WindowAdapter( )
public void windowClosing(WindowEvent e)
message=-1;setVisible(false);
);

public void actionPerformed(ActionEvent e)
if(e.getSource( )==yes)
message=YES;
setVisible(false);

else if(e.getSource( )==no)
message=NO;
setVisible(false);


public int getMessage( )
return message;


class Dwindow extends Frame implem
[填空题]下面程序运行后显示一个窗口,在窗口中有一个按钮和一个标签,单击按钮,标签中显示按钮被单击的次数,请完成程序。
import java. awt.*;
import javax. swing.*;
import java. awt. event.*;
class myFrame extends JFrame implements ActionListener

JButton button;
JLabel label;
myFrame(String s)

super(s);
Container con=______;
setLayout(new FlowLayout( ));
setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
setSize(300,400);
button=new JButton("OK");
label=new JLabel("0");
con. add(button);con.add(label);
button. addActionListener(this);
setVisible(true);

public void actionPerformed(ActionEvent e)

int n=______;
n++;
label. setText(" "+n);


public class C2801

public static void main(String[] args)

new myFrame("我的窗口");


[简答题]下面是一个Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,单击按钮,可以在文本区已有的文本基础上追加显示10条“欢迎您,参加Java考试!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
源程序文件代码清单如下;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
<applet code="ex13_3.class" width=800 height=400>
</applet>
public class ex13_3 extends JApplet

JButton jb = new JButton("Add Text");
JTextPane jtp = new JTextPane( );
public void init( )

jb.addActionListener(new ActionListener( )

public void actionPerformed(ActionEvent e)

for(int i=1; i<10; i++)
jtp.getText(jtp.setText( )+
"欢迎您,参加Java考试!");

);
Container cp = getContentPane( );
cp.add(new JScrollPane(jtp));
cp.add(BorderLayout. SOUTH, jtp);

public static void main(String args[])

ex13_3 obj13_3=new ex13_3( );
String str =
[填空题]本题中定义了一个树型的通信录,窗口左侧是一个树,右侧是一个文本域,单击树的结点,则在右侧文本域中显示相关信息,如果单击的是树结点,则显示对应名字的电话信息。
import javax. swing. * ;
import javax. swing. tree. * ;
import java. awt. * ;
import java. awt. event. * ;
import javax. swing. event. * ;
class Mytree2 extends JFrame______
JTree tree=null; JTextArea text=new JTextArea(20,20);
Mytree2( )
Container con=getContentPane( );
DefauhMutableTreeNode root=new DefauhMutableTreeNode ("同学通信录");
DefaultMutableTreeNode t1=new DefauhMutableTreeNode("大学同学");
DefaultMutableTreeNode t2=new DefaultMutableTreeNode("研究生同学");
DefaultMutableTreeNode t1_1=new DefauhMutableTreeNode("陈艳");
DefauhMutableTreeNode t1_2=new DefaultMutableTreeNode("李小永");
DefauhMutableTreeNode t2_1=new DefaultMutableTreeNode("王小小");
DefaultMutableTreeNode t2_2=new DefaultMutableTreeNode("董小");
setTitle("java2");
root. add(t1); root. add(t2);
t1. add(t1_1); t1, add(t1_2); t2. add(t2_1); t2. add(t2_2);
tree=
[简答题]本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为“鼠标的当前位置: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);

[简答题]本题程序的功能是主窗口有一个按钮、一个文本域和一个复选框,初始时窗口的大小是不能调整的,勾选复选框后,窗口大小就可以进行调整,如果取消勾选复选框,则窗口的大小又不能调整,单击按钮可以关闭程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
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


[简答题]本题程序的功能是使用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;

[填空题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“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
[简答题]本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“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
[单项选择]在一个已打开的Foxpro表中要增加一个字段,应在“项目管理器”窗口中单击按钮
A. 添加
B. 浏览
C. 修改
D. 移去
E. 数据
[单项选择]窗体中有3个按钮Command1、Command2和Command3,该程序的功能是当单击按钮Command1时,按钮2可用,按钮3不可见,正确的程序是 Private Sub Command1_Click( ) Command2. Visible=False Command3. Enabled=True End Sub Private Sub Commnd1_Click( ) Command2. Visible=False Command3. Enabled=False End Sub Private Sub Command1_Click( ) Command2. Enabled=True Command3. Visible=False End Sub Private Sub Command1_Click( ) Command2. Visible=True Command3. Enabled=True End Sub

我来回答:

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

订单号:

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