P
phil89
Hi,
I could not have Keyboard event when i have an Scorllbar into my
applet ?
Could you help me
Thanks
Philippe
package scroll;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class EssaiAscenseur4 extends Applet implements
AdjustmentListener,
MouseListener
,KeyListener
,ComponentListener
{
int decalageH=0;
int decalageV=0;
int largeurFenetre=300;
int hauteurFenetre=200;
Vector memoire=new Vector();
Scrollbar vbar=new Scrollbar
(Scrollbar.VERTICAL,0,(int)(hauteurFenetre * 0.9),0,1000);
Scrollbar hbar=new Scrollbar
(Scrollbar.HORIZONTAL,0,(int)(largeurFenetre * 0.9),0,500);
Color couleur=Color.magenta;
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
addMouseListener(this);
addKeyListener(this);
addComponentListener(this);
setLayout(new BorderLayout());
vbar.addAdjustmentListener(this);
hbar.addAdjustmentListener(this);
vbar.setBlockIncrement((int)(hauteurFenetre * 0.9));
hbar.setBlockIncrement((int)(largeurFenetre*0.9));
//Fonctionne des que ces deux lignes sont enleve ou si on extends
de frame et pas de APPLET
add("East",vbar);
add("South",hbar);
setForeground(couleur);
}
// Pour gerer le Decalage
public void adjustmentValueChanged(AdjustmentEvent evt)
{
if (evt.getSource()==vbar) decalageV=evt.getValue();
else if (evt.getSource()==hbar) decalageH=evt.getValue();
repaint();
}
public void mousePressed(MouseEvent evt)
{
CercleSitue c;
Graphics g=getGraphics();
int x=evt.getX(),y=evt.getY();
c=new CercleSitue(10,x+decalageH,y+decalageV);
g.fillOval(x-20,y-20,40,40);
memoire.addElement(c);
}
public void mouseReleased(MouseEvent evt) {}
public void mouseEntered(MouseEvent evt) {}
public void mouseExited(MouseEvent evt) {}
public void mouseClicked(MouseEvent evt) {}
public void keyReleased(KeyEvent evt) {
}
public void keyPressed(KeyEvent evt) {
System.out.println("PRESSED");
}
public void keyTyped(KeyEvent evt) {
}
public void componentResized(ComponentEvent e)
{
System.out.println("ddd screen
height="+Toolkit.getDefaultToolkit().getScreenSize().getHeight()+"
screen
width="+Toolkit.getDefaultToolkit().getScreenSize().getWidth());
}
public void componentHidden(ComponentEvent e) {
}
public void componentShown(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void paint(Graphics g)
{
Enumeration lesCercles=memoire.elements();
CercleSitue c;
while(lesCercles.hasMoreElements())
{
c=(CercleSitue)lesCercles.nextElement();
g.fillOval(c.x-20-decalageH,c.y-20-decalageV,40,40);
}
}
public static void main (String[] args)
{
EssaiAscenseur4 applet = new EssaiAscenseur4();
Frame frame = new Frame();
frame.addWindowListener(new WindowAdapter() { public void
windowClosing(WindowEvent e) { System.exit(0); } } );
frame.add(applet, BorderLayout.CENTER);
frame.setTitle( "Applet Frame" );
applet.init();
applet.start();
frame.setSize(800, 800);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((d.width-frameSize.width)/2, (d.height-
frameSize.height)/2);
frame.setVisible(true);
}
}
I could not have Keyboard event when i have an Scorllbar into my
applet ?
Could you help me
Thanks
Philippe
package scroll;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class EssaiAscenseur4 extends Applet implements
AdjustmentListener,
MouseListener
,KeyListener
,ComponentListener
{
int decalageH=0;
int decalageV=0;
int largeurFenetre=300;
int hauteurFenetre=200;
Vector memoire=new Vector();
Scrollbar vbar=new Scrollbar
(Scrollbar.VERTICAL,0,(int)(hauteurFenetre * 0.9),0,1000);
Scrollbar hbar=new Scrollbar
(Scrollbar.HORIZONTAL,0,(int)(largeurFenetre * 0.9),0,500);
Color couleur=Color.magenta;
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
addMouseListener(this);
addKeyListener(this);
addComponentListener(this);
setLayout(new BorderLayout());
vbar.addAdjustmentListener(this);
hbar.addAdjustmentListener(this);
vbar.setBlockIncrement((int)(hauteurFenetre * 0.9));
hbar.setBlockIncrement((int)(largeurFenetre*0.9));
//Fonctionne des que ces deux lignes sont enleve ou si on extends
de frame et pas de APPLET
add("East",vbar);
add("South",hbar);
setForeground(couleur);
}
// Pour gerer le Decalage
public void adjustmentValueChanged(AdjustmentEvent evt)
{
if (evt.getSource()==vbar) decalageV=evt.getValue();
else if (evt.getSource()==hbar) decalageH=evt.getValue();
repaint();
}
public void mousePressed(MouseEvent evt)
{
CercleSitue c;
Graphics g=getGraphics();
int x=evt.getX(),y=evt.getY();
c=new CercleSitue(10,x+decalageH,y+decalageV);
g.fillOval(x-20,y-20,40,40);
memoire.addElement(c);
}
public void mouseReleased(MouseEvent evt) {}
public void mouseEntered(MouseEvent evt) {}
public void mouseExited(MouseEvent evt) {}
public void mouseClicked(MouseEvent evt) {}
public void keyReleased(KeyEvent evt) {
}
public void keyPressed(KeyEvent evt) {
System.out.println("PRESSED");
}
public void keyTyped(KeyEvent evt) {
}
public void componentResized(ComponentEvent e)
{
System.out.println("ddd screen
height="+Toolkit.getDefaultToolkit().getScreenSize().getHeight()+"
screen
width="+Toolkit.getDefaultToolkit().getScreenSize().getWidth());
}
public void componentHidden(ComponentEvent e) {
}
public void componentShown(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void paint(Graphics g)
{
Enumeration lesCercles=memoire.elements();
CercleSitue c;
while(lesCercles.hasMoreElements())
{
c=(CercleSitue)lesCercles.nextElement();
g.fillOval(c.x-20-decalageH,c.y-20-decalageV,40,40);
}
}
public static void main (String[] args)
{
EssaiAscenseur4 applet = new EssaiAscenseur4();
Frame frame = new Frame();
frame.addWindowListener(new WindowAdapter() { public void
windowClosing(WindowEvent e) { System.exit(0); } } );
frame.add(applet, BorderLayout.CENTER);
frame.setTitle( "Applet Frame" );
applet.init();
applet.start();
frame.setSize(800, 800);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((d.width-frameSize.width)/2, (d.height-
frameSize.height)/2);
frame.setVisible(true);
}
}