Professional Documents
Culture Documents
a)
S dng file MouseEventViewer.java hon thnh on m sau bng cch ng k cho php
hin th cc dng tng ng trong lp MouseHandler.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MouseEventViewer extends JFrame
{
public static final int WIDTH = 300;
public static final int HEIGHT = 200;
public MouseEventViewer()
{
super();
setSize(WIDTH, HEIGHT);
setLocation(30, 40);
// register the window listener to close the window
// register the mouse listener to respond to all mouse events
}
private class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
private class MouseHandler extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
System.out.println("MOUSE EVENT: Mouse Pressed");
}
// similarly override all the other methods in MouseAdapter
}
public static void main(String[] args)
{
MouseEventViewer myWindow = new MouseEventViewer();
myWindow.setVisible(true);
}
}
b)
Bi 2.
Vit mt lp KeyEventViewer vi 2 lp con tng t nh cu 1 nhng s dng lp KeyHandler
thay v MouseHandler. Vit cc u ra tng t cho mi phng thc KeyHandler khi xy ra
s kin tng ng.
Laboratory 12
Bi 3.
Sa file ButtonDemoLab.java thnh v d nh sau:
a)
b)
c)
Bi 4.
To mt ng dng c tn PanelDemo.java to mt ca s vi 2 vng chnh (tri v phi), s dng
panels. Khung bn phi c 3 nt radio cho php i mu nn khung bn tri (Xem hnh)
Mu ban u l mu
Bi 5.
To mt ng dng SlideDemo.java c 3 slide bar, mt nt nh hnh di. Cc thnh slide c gi tr
t 0 255, v khi nt c bm, mt ca s mi (tn l Popup Window) hin ra cho bit gi tr
cc mu cng nh hin th mu (mu nn). C th thm cc tick mark hoc cc tick label cho cc
thanh trt.
[Note you may find that setSize and setMinimumSize() are not enforced on JFrame in some
situations in some windows environments. The sub-window may need to be manually resized in
our lab set-up.]
2
Laboratory 12
Bi 6.
To ng dng my tnh n gin Calculator.java. My tnh c kh nng tnh ton 4 php ton c
bn l +, -, *, / vi s thc. Ngi dng nhp s th nht v s th hai vo 2 trng vn bn, php
tnh c thc hin khi ngi dng nhn php tnh tng ng. Nt clear dng xa c 3 trng
vn bn
Laboratory 12
Laboratory 12