题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-10-22 21:51:37

[填空题]本题的功能是定义自己的组件类。窗口中排布着12个按钮,鼠标移动按钮时,按钮背景颜色改变,用鼠标单击按钮时,后台将显示该按钮对应的字符。
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class java3 extends Frame
String keys="123456789*0#";
java3( )
super("java3");
addWindowListener(new WindowAdapter( )
public void windowClosing(WindowEvent e)
System.exit(0);
);

setLayout(new GridLayout(4,3,6,6));
for(int i=0;i<keyslength;i++))
KeyButton kb=new KeyButton(keys.charAt(i));
kb.addkeyListener(this);
kb.setBackground(C010r.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)
new java3( );


class KeyButton extends Component
KeyListener keyListener;
boolean highlighted;
cha

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

[简答题]本题的功能是定义自己的组件类。窗口中排布着12个按钮,鼠标移动按钮时,按钮背景颜色改变,用鼠标单击按钮时,后台将显示该按钮对应的字符。
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class java3 extends Frame
String keys="123456789*0#";
java3( )
super("java3");
addWindowListener(new WindowAdapter( )
public void windowClosing(WindowEvent e)
System.exit(0);

);
setLayout(new GridLayout(4,3,6,6));
for(int i=0;i<keyslength;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)
new java3( );


class KeyButton extends Component
KeyListener keyListener;
boolean highlighted;
char
[简答题]本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“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
[单项选择]窗体中有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
[填空题]本题的功能是监听键盘键的敲击,并显示在窗口中。
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
[填空题]本题是一个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]);




[多项选择]本题中定义了一个带有参数的构造方法java1( ),并定义了一个该类的对象temp。构造方法java1( )有两个参数:字符串name和整型age。定义对象temp时将字符串“Tom”和整数17传递给构造方法,构造方法将这两个参数打印输出。
public class java1
String name;
int age;
public static void main(String[]args)
String name="Tom";
int age=17;
java1 temp=______;

public java1(String name,______)
______;
this.age=age;
System.out.println(name+"is"+age+"years old.");


[单项选择]下列程序的功能是调用字体对话框来设置文本框字体,单击按钮弹出对话框后,按Cancel 键退出对话框,则( )。   Private Sub Command1_Click( )   CommonDialogl.CancelError=True   CommonDialogl.Flags=cdlCFEffects Or cdlDFBotb   CommonDialogl.Action=4   CommonDialogl.ShowFont   Text1.Font.Name=CommonDialogl.FontName   Text1.Font.Size=CommonDialogl.FontSize   Text1.Font.Bold=CommonDialog1.FontBold   Text1.Font.Italic=CommonDialog1.FontItalic   Text1.Font.Underline=CommonDialog1.FontUnderline   Text1.FontStrikethru=CommonDialog1.FontStrikethru   Text1.ForeColor=CommonDialog1.Color  End Sub
A. Text1的字体不发生变化
B. Text1的字体发生变化
C. Text1的字体和颜色发生变化
D. 程序出错!
[简答题]本题程序的功能是:单击窗口左上角的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

我来回答:

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

订单号:

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