|
|
Help me to understand, pls.
Hi,
Here is the applet, which displays a red x. It should display a
letter and a number when I type a key. The problem is line //a and
//b. Why do they cause problem? Why does it show a red x?
If I do not use these two lines and use a line
this.requestFocus();
it does not work either. But why? Since line //c is ok. What's wrong
with "this."? Line //c does not cause any problem. But I still need
to click the applet to get the focus. It seems there is no way to set
focus thru code on the applet.
Below is the code. Thanks a lot - Chris
import java.applet.*;
import java.awt.*;
public class Echo extends Applet {
int m;
Echo st=new Echo();//a
public void init() {
//requestFocus();//c
st.requestFocus();//b
setBackground(Color.pink);
}
public void paint(Graphics g) {
if (!(m==0)){
g.drawString(Integer.toString(m),100,100);
g.drawString("" + (char)m,200,200);
g.drawString("test" + 1,200,300);}
}
public boolean keyDown(Event evt, int key) {
m=key;
repaint();
return true;
}
}
|
|
0
|
|
|
|
Reply
|
yma2037 (32)
|
2/28/2004 2:34:13 AM |
|
On 27 Feb 2004 18:34:13 -0800, chirs wrote:
> import java.applet.*;
> import java.awt.*;
to detect an event you will most
likely need to..
import java.awt.event.*;
>
> public class Echo extends Applet {
> int m;
> Echo st=new Echo();//a
You do not need to instantiate
applets like this, the applet
tag causes the init() method
to be called.
> public void init() {
>
> //requestFocus();//c
> st.requestFocus();//b
> setBackground(Color.pink);
> }
>
> public void paint(Graphics g) {
> if (!(m==0)){
> g.drawString(Integer.toString(m),100,100);
> g.drawString("" + (char)m,200,200);
> g.drawString("test" + 1,200,300);}
> }
>
> public boolean keyDown(Event evt, int key) {
keydown is deprecated, but since you
did not have it attached to anything,
it makes little difference.
> m=key;
> repaint();
> return true;
> }
> }
You might get some benefit from
looking at a working example that
detects keyevents, have a look at..
<http://www.physci.org/launcher.jsp#StringTokenizerFrame>
that links to source and a button to
launch it. The KeyEvent is actioned
at line 83.
Perhaps you should be consulting the
basic tutorials and JavaDocs a bit more,
and for the moment posting over at
comp.lang.java.help
--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
|
|
0
|
|
|
|
Reply
|
SeeMySites (3836)
|
2/28/2004 3:12:49 AM
|
|
|
1 Replies
36 Views
(page loaded in 0.051 seconds)
Similiar Articles: Please help me understand this - comp.soft-sys.matlabhey every one,here is my problem,I found a code which doing the following to an image fftshift(fft2(image)) then he apply Gaussian high pass filter ... GUI: Fortran + Visual Basic - comp.lang.fortranWould you please help me with this! I want to know whether this is a good job or it is better to write both GUI and computational parts with Visual Fortran (as you know ... Data tranfer rate calculation for Disk storage. - comp.arch ...Hi, I am totally dumb on this question. Please someone can help me to know how to calculate this one. Question: -->>>A disk unit has 20 recording ... Pivot table in SAS - comp.soft-sys.sasI have BASE/SAS ,SAS/GRAPHS,SAS/ACCESS to ODBC pls help me.. i am not able to understand the code properly..t he step by step procedure... Thanks in advance ... How can I know "blocksize" of os - comp.unix.solarisHello... Thank you for your advice every day..^^; I want to know blocksize of os..(SunOS). What are the command to know it..? pls. help me...Thanks. Help to calculate time complexity of a program - comp.soft-sys ...... to know how to calculate the time complexity of my program because it uses many MATLAB in-built functions. The McCabe complexity of the code written is 13. Please help me ... I have problem with connect to MySQL server please help me ...I have problem with connect to MySQL server please help me ... Connecting to mySQL database over the LAN - comp.databases.mysql ... I have ... Please help me understand ... PKGADD Error - comp.unix.solarisI don't know how to set the environment > > > variable. Can anyone help me please. > > > > > > > In sh ( the default root shell ) execute: > > > > # TMPDIR=/path/to/new ... Re: Running with V8 and V9 - Please help me - comp.soft-sys.sas ...Really I didn't understand. > > > > Please help me on this. Any help I will greatly thankful... > > > > Thanks in advance > > Chandu. > > how to append a value to an existing xml document - comp.lang.idl ...Hi All, I need to know how to append a value to an existing xml document. Could anyone help me please! Thanks, Truong ... The genuine cry of many...God Help me Please! I need someone to ...You may not know me, but I know everything about you — Psalm 139:1.....I know when you sit down and when you rise up — Psalm 139:2.....I am familiar with all your ... God Please Help Me – Prayer for Strength and Healing ...Let me clarify something that is very important to understand. When I say, "God please help me," I am not coming from a place where I think God might turn down my request. 7/11/2012 5:36:27 AM
|
|
|
|
|
|
|
|
|