HFJava_393_396.pdf
(
976 KB
)
Pobierz
getting
gui
public MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) {
MidiEvent event = null;
try {
ShortMessage a = new ShortMessage();
a.setMessage(comd, chan, one, two);
event = new MidiEvent(a, tick);
}catch(Exception e) { }
return event;
}
// close method
class MyDrawPanel extends JPanel implements ControllerEventListener {
boolean msg = false;
public void controlChange(ShortMessage event) {
msg = true;
repaint();
}
public void paintComponent(Graphics g) {
if (msg) {
Graphics2D g2 = (Graphics2D) g;
int r = (int) (Math.random() * 250);
int gr = (int) (Math.random() * 250);
int b = (int) (Math.random() * 250);
g.setColor(new Color(r,gr,b));
int ht = (int) ((Math.random() * 120) + 10);
int width = (int) ((Math.random() * 120) + 10);
int x = (int) ((Math.random() * 40) + 10);
int y = (int) ((Math.random() * 40) + 10);
g.fillRect(x,y,ht, width);
msg = false;
} // close if
} // close method
} // close inner class
} // close class
you are here
4
393
puzzle:
Pool Puzzle
import javax.swing.*;
import java.awt.*;
public class Animate {
int x = 1;
int y = 1;
public static void main (String[] args) {
Animate gui = new Animate ();
gui.go();
}
public void go() {
JFrame _________ = new JFrame();
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
______________________________________;
_________.getContentPane().add(drawP);
__________________________;
_________.setVisible(true);
for (int i=0; i<124; _______________) {
_____________________;
_____________________;
try {
Thread.sleep(50);
} catch(Exception ex) { }
}
}
class MyDrawP extends JPanel {
public void paintComponent (Graphic
_________) {
__________________________________;
__________________________________;
__________________________________;
__________________________________;
}
}
}
Pool Puzzle
Your
job
is to take code snippets from
the pool and place them into the blank
lines in the code. You
may
use the
same snippet more than once,
and you won’t need to use all the
snippets. Your
goal
is to make a
class that will compile and run
and produce the output listed.
Output
The Amazing, Shrinking, Blue Rectangle.
This program will produce a blue
rectangle that will shrink and shrink and
disappear into a field of white.
Note: Each snippet
from the pool can be
used more than once!
g.fillRect(x,y,x-500,y-250)
g.fillRect(x,y,500-x*2,250-y*2)
g.fillRect(500-x*2,250-y*2,x,y)
g.fillRect(0,0,250,500)
g.fillRect(0,0,500,250)
g
draw
frame
panel
i++
i++, y++
i++, y++, x++
Animate frame = new Animate()
MyDrawP drawP = new MyDrawP()
ContentPane drawP = new ContentPane()
x++
y++
g.setColor(blue)
g.setColor(white)
g.setColor(Color.blue)
g.setColor(Color.white)
drawP.paint()
draw.repaint()
drawP.repaint()
drawP.setSize(500,270)
frame.setSize(500,270)
panel.setSize(500,270)
396
chapter 12
Plik z chomika:
keler1973
Inne pliki z tego folderu:
hfjavafinalsamples.zip
(181 KB)
codeKitchensTiger.jar
(34 KB)
HFJava_393_396.pdf
(976 KB)
Inne foldery tego chomika:
EJB_code_&_answers
Head.First.iPhone.Development_code&answers
HFAjax_code&answers&files_to_view
HFDesignPatterns_code&answers
HFHtml_code&answers
Zgłoś jeśli
naruszono regulamin