🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.java
1 messages
1 total messages Started by Artur Tyloch Mon, 29 Sep 1997 00:16
KeyEvent "na" panelu
#1075
Author: Artur Tyloch
Date: Mon, 29 Sep 1997 00:16
64 lines
2420 bytes
Czesc.

Moze ktos spojrzy i bedzie wiedzial?

Ma byc: po nacisnieciu klawisza na klawiaturze, na panelu wypsuje HELLO
(wersja minimum
:) )
Jest: nic sie nie dzieje.

Czy zdarzenie KeyEvent jest mozliwe dla obiektow takich jak 
np. Button czy moze byc uzyte tez dla np. panel'u czy apletu?


Jest juz pozno i moze cos pomijam...? [ide spac!]

Probowalem to zrobic tak:

//test KeyListener
 public class MojApletKAnonim extends Applet
 {
  Panel panel = new Panel();
  Graphics panelKG;     
  int mouseX,mouseY;
  public void start()
  {                     
        panel.setBackground(Color.yellow);
        setLayout(new BorderLayout());
        add("Center",panel);
        panelKG = panel.getGraphics();

        //addKeyListener(  // < tez nie dziala
        panel.addKeyListener(  
                new KeyAdapter() 
                {
                  public void keyTyped(KeyEvent evt)
                  {
                    String ch =evt.getKeyText(evt.getKeyCode());
//=======================================
                    //tu nie wypisuje "HELLO" na panelu!? Why   
                    panelKG.drawString("HELLO",20,20); 
//mouseX,mouseY);
//=======================================
                  }
                }
        );
        panel.addMouseListener(
                new MouseAdapter() 
                {
                  public void mouseClicked(MouseEvent evt)
                  {
                    mouseX = evt.getX();
                    mouseY = evt.getY(); 
//====================== \/
                    // a tu dziala !
                    panelKG.drawString("to"+mouseX,10,10);
                  }
                }
        );              
  }
}

pozdrawiam
A/.t
mailto:arturt@friko.onet.pl
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads