Questions about Applet and JFrame

Reply

Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Questions about Applet and JFrame

 
0
  #1
Dec 20th, 2007
Hello,

I'm creating a program that will be dealing with multiple objects that extend Applet and a JFrame that will be displaying them. I created a test that swiched off between two applets I made. While I was creating the test, I noticed some things and have few questions regarding Applet and JFrame.

My first test involved one new applet and one I created that was used by an html file. From that test I realized the web applet failed to run (null pointer exceptoin). Why would an applet that normally works on web, fail to run in a JFrame? Particularly fails when init() is called.

After working around the issue of the first test by creating a different applet, there was another thing I noticed, the applet was covered by the frame of the window. How do I correct this issue?

Another issue I noticed is that after the switch I would need to click on the applet before KeyListener would work. How do I work around this?

The last question I have is if the code below is a good way to go or if there's a better way?

here's the code for the making the swich...
public void keyReleased(KeyEvent e)
{
//Gg is one the applets
Gg g = new Gg();
g.addKeyListener(g);

g.setSize(300,300);

//ex is the JFrame
ex.add(g);
ex.remove(this);
ex.validate();
Last edited by Mr.UNOwen; Dec 20th, 2007 at 8:18 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: Questions about Applet and JFrame

 
0
  #2
Dec 26th, 2007
Ok I just figured out some of my problems, but I still can't figure out how to make 0,0 be corner of the showing applet. Does anyone know how get applet not to go into border of the window? Do I have to adjust everything or is there a simpler way?

Also in my program the user will be able to choose their controls. What listener will allow me to listen to any button press whether it be from keyboard, mouse, game pad, or joy stick?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 44
Reputation: arunpawar is an unknown quantity at this point 
Solved Threads: 0
arunpawar arunpawar is offline Offline
Light Poster

Re: Questions about Applet and JFrame

 
0
  #3
Dec 26th, 2007
YOu can get away with borders if you want.just look at the actionlistener interface in javadocs for keyborad and mouse event.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: Questions about Applet and JFrame

 
0
  #4
Dec 26th, 2007
If I use actionlistener, where do I add it? There's no addActionListener in JFrame or applet.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: Questions about Applet and JFrame

 
0
  #5
Dec 31st, 2007
Does anyone know how to get an applet to fit properly in a JFrame, such that it doesn't go into edges of the window?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,346
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 498
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #6
Dec 31st, 2007
Why on earth are you putting an Applet in a JFrame?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: Questions about Applet and JFrame

 
0
  #7
Dec 31st, 2007
Well I got some of my issues out of the way, can someone now tell me how to keep the key listener on the applet after I switch from one applet to another? Also If I want to make the window transparent, how would I go about doing that?

Why I'm using applet:
Well first of all I'm not that experienced with java so I don't know what's the right way or the wrong way to do anything. The reason I did it that way is because I saw it done that way.

Second what I thought was going out of the borders, wasn't doing that. So that issue is out of the way.

Third I wanted to use multiple applets such that each represented an individual screen such that one would be the menu screen and so on.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,346
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 498
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #8
Dec 31st, 2007
Applets are typically only used for small programs embedded in web-pages. If you are developing a regular desktop Java app then you would use JFrames and JPanel sub-components. The individual screens that you describe could be either one, depending upon how many top-level windows you wish to have.

JPanels are not standalone top-level windows, but can be placed in any other container component, such as JFrame, JSplitPane, JScrollPane, JTabbedPane, etc. By developing smaller classes that extend JPanel, you can easily create "sub-forms" that can be placed into containers in any manner you chose.

This tutorial covers a lot of these things in detail:
http://java.sun.com/docs/books/tutor...ing/index.html

Most everything that you have coded so far can probably be moved to a JPanel with only minimal effort. Anything in init() can probably be done in the constructor. Code in start() may be okay in the constructor or perhaps a public method, depending upon what that code is doing.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: Questions about Applet and JFrame

 
0
  #9
Dec 31st, 2007
Thanks for the info Ezzaral.
Got any links on how to produce a UI that can be any shape or size (in other words, get whatever is behind the window and display it before anything else)? Or is there a way to get the background transparent and not just a dull grey?

Also what's the best way to create a program with a set fps? A new thread or through an action listener that listens to a timer?
Last edited by Mr.UNOwen; Dec 31st, 2007 at 10:19 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,346
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 498
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #10
Jan 2nd, 2008
I don't really understand what you mean with the first question.

As far as animation timing, take a look at this article: http://www.developer.com/java/article.php/893471
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC