The Artima Developer Community
Sponsored Link

Java Answers Forum
please help me with my applet

28 replies on 2 pages. Most recent reply: Sep 3, 2003 10:50 AM by assan rekowski

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 28 replies on 2 pages [ « | 1 2 ]
assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: THANKS FOR HELPING!!!! :) Posted: Sep 2, 2003 10:36 AM
Reply to this message Reply
Advertisement
And what is in Frame? Frame = browser window? or Frame = applet, why to put concrete frame in my variablr Frame, can't i do only Frame frame = new Frame()
instead of Frame frame = ComponentUtilities.getTopLevelParent(aplet); ?

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: THANKS FOR HELPING!!!! :) Posted: Sep 2, 2003 10:48 AM
Reply to this message Reply
And why if i change Component to Container it works ?

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

ANOTHER QUESTION Posted: Sep 2, 2003 5:39 PM
Reply to this message Reply
I'am beginnig to understand know... thanks!, but still not all... i have many qouestions i know, and i ask again :)
the button "Wiek" in my project is "Age" button, the textfield next to it should't take more than 3 signs, the visitor can't have such possibility. SO i created
not TextField Wiek(5); but FieldAge Wiek(5); and
Wiek.Slucha() at the beginning of my project in function Init(), it doesnt works - it hears when i press the key
and the condition
if (ile>3) is being checked, but the letter that i pressed i already in the TextField and it's too late to drop the event - "ile" is grater than 3, what is wrong with that class?

class FieldAge extends TextField implements KeyListener {

boolean Testuj(TextField pole){
return true;
}
boolean Sluchaj(){
//this.
addKeyListener(this);
return true;
}

public void keyReleased(KeyEvent evt)
{
String Rob = new String();
int ile;
try
{

Rob=this.getText();

}
catch (Exception e) {

}
ile=Rob.length();
if (ile>3){
//Rob.
return;
// break;
}
char znak = evt.getKeyChar();
int kod = evt.getKeyCode();
String nazwa = evt.getKeyText(kod);
}
public void keyPressed(KeyEvent evt)
{
char znak = evt.getKeyChar();
int kod = evt.getKeyCode();
String nazwa = evt.getKeyText(kod);
}

public void keyTyped(KeyEvent evt)
{
char znak = evt.getKeyChar();
int kod = evt.getKeyCode();
String nazwa = evt.getKeyText(kod);
}
FieldAge(){

}

}

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: ANOTHER QUESTION Posted: Sep 2, 2003 11:39 PM
Reply to this message Reply
Your questions in bold and my understandings in italic...


but i dont uderstand the class ComponentUtilities, what does it do? why there is this loop "for"? What does it mean return (Frame)c;




Class ComponentUtilities is an Helper class to find who is a Parent of a component.You can make your piece of code run without ComponentUtilities.
Use the following line of code.
Frame frame = (Frame)aplet.getParent();
//Instead of 
 
//Frame frame = ComponentUtilities.getTopLevelParent(aplet);
//in MessageWindow
 


return (Frame)c means the component c is typecaste into Frame and then returned.




Besides please tell me, why after removing line java.awt.Point aploc = aplet.getLocation();
it still working good?





Because after
java.awt.Point aploc = aplet.getLocation();

aploc is not used anywhere.
You could use the location of applet aploc in the following piece of cod
tn.setLocation(200, 300); //here u can set location relative to ur aploc values so that u can adjust ur window in the center of applet.





and why when i change
public static Frame getTopLevelParent(Component component) to public static Frame getTopLevelParent(Applet component)




Because component is the parent of Applet.If you use Applet component u can not use that method for other componennts althouh it may work fine for ur case.
It was simply a generic method to accomodate all case.
Heirarchy is as


<pre>
java.lang.Object
|
+-java.awt.Component
|
+-java.awt.Container
|
+-java.awt.Panel
|
+-java.applet.Applet
</pre>




And how to make black thin borders around my applet




Hmm what i think of it as of now is in ur html add applet tag to a table and set border to htnl table

<table cellspacing=0 cellpadding=0 vspace=0 border=1 >
<tr>
<td>
<APPLET height=349 width=505 code=QueryApplet.class VIEWASTEXT>
</APPLET>
</td>
</tr>
</table>


or pass a parameter border to ur applet and read
s2 = getParameter("border");
boolean border = s2 != null && (s2.charAt(0) == 'y' || s2.charAt(0) == 'Y');

and use the following two methods in ur applet

public void paint(Graphics g)
 {
     update(g);
 }
 
public void update(Graphics g)
{
	if (border)
	{
		Dimension dimension = size(); //actually size() is depreciated.Better to use getSize() if u have jdk after JDK1.1
		g.setColor(Color.black);
		g.drawRect(0, 0, dimension.width - 2, dimension.height - 2);
		g.drawRect(1, 1, dimension.width - 4, dimension.height - 4);
	}
}
 




And why if i change Component to Container it works ?



See the hierarchy...conatiner extends component so it works




Now ur class Field Age




First of all ur method Sluchaj() is not getting called so listner is not added to ur FiledAge.

Change ur constructor like

FieldAge(){
  super();
  Sluchaj();
}


And modify ur public void keyReleased(KeyEvent evt) method to include
ile=Rob.length();
if (ile>=3){
	this.setText(Rob.substring(0,3));
	this.setCaretPosition(3);
return;
// break;
}
 



Hope that will help...I think i need a break now..what do u say

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: ANOTHER QUESTION Posted: Sep 3, 2003 1:17 AM
Reply to this message Reply
By the where are u frm....??

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Thanks, it will work Posted: Sep 3, 2003 5:19 AM
Reply to this message Reply
Poland - > city £ódŸ 890000 inhabitants, completly destroyed by Hitler in '39-'44

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 5:53 AM
Reply to this message Reply
it's funny :) u should taka a look how it works now, try to input some value in Age , fourth number always appears and immediatelly disappears, besides the age is changing .
http://www.toya.net.pl/~grupaie2/BARTEK.zip

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 6:18 AM
Reply to this message Reply
there was my error, there should be
this.setText(Rob.substring(0,3));
this.setCaretPosition(3);
i did
this.setCaretPosition(3);
this.setText(Rob.substring(0,3));
but still after u press the fourth number ,it is visible for a short while.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 6:25 AM
Reply to this message Reply
MY MISTAKE ..USE THIS AS CODE..actually i didnt test that..simply used ur code...

import java.awt.*;
import java.awt.event.*;
class FieldAge extends TextField implements KeyListener
{
	int size = 3;
	
	FieldAge()
	{
		super();
		Sluchaj();
		size =3;
	}
	
	FieldAge(int i)
	{
		super(i);
		size = i;
		Sluchaj();
	}
	
	boolean Sluchaj()
	{
		//this.
		addKeyListener(this);
		return true;
	}
 
public void keyReleased(KeyEvent evt)
{
}
 public void keyPressed(KeyEvent e)
    {
        if(e.isActionKey())
            return;
        char key = e.getKeyChar();
        if(e.getKeyCode() == 127 || key == '\b' || key == '\t')
            return;
        if(size > 0)
        {
            int curlen = ((TextField)e.getComponent()).getText().length();
            if(curlen >= size)
            {
                e.consume();
                return;
            }
        }
        if(Character.isLetter(key) || Character.isSpaceChar(key) || key == '-')
        {
            e.consume();
            return;
        } 
		else
        {
            return;
        }
    }
 
 
public void keyTyped(KeyEvent evt)
{
}
 
}



Now loook
int size = 3; is initally set to 3..to make it more genric u can initalize it with 0 and in costructor
FieldAge()

set size = 0 also.

Later on call from applet....

FieldAge wiekFld = new FieldAge(3);

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 6:26 AM
Reply to this message Reply
Note...This will allow u to enter only number in ur number text field...
Okey sir... :)

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 7:04 AM
Reply to this message Reply
all work is almost finished. But how u know all of it?
have any god books? i have only one bary boone "java for c c++ programmers", there is nothing,how to cope with such problems in my project, only by searching in Help?

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 8:17 AM
Reply to this message Reply
Goood Boook....yeah there are good books in market...loook at

http://java.sun.com/docs/books/tutorial/

morover there is a book a complete refrence for java 2 ...if i will find a softcopy of that with me I will mail u...
mail id sir... :)

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 10:22 AM
Reply to this message Reply
and where can i find all informations about different keys have their int equivalent,
if(e.getKeyCode() == 127 || key == '\b' || key == '\t')

what is 127?

Character.isLetter(key) Character - function that hasn't
anything on the left side? like e.Character...
why

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: Thanks, it will work Posted: Sep 3, 2003 10:50 AM
Reply to this message Reply
found it, thanks 4 all

Flat View: This topic has 28 replies on 2 pages [ « | 1  2 ]
Topic: i want to check if a string exists in a file Previous Topic   Next Topic Topic: How to invoke a java program ( service ) which resides at Remote machine?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use