Questions about Applet and JFrame

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
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

Re: Questions about Applet and JFrame

 
0
  #11
Jan 2nd, 2008
So lets say I want a window in the shape of a circle, I need to have that gray undecorated square window to be transparent such that I can draw a circle such that it looks as though the window is in the shape of a circle. So is there a way to A, get what's displayed behind the window and display it or B, make the gray color be transparent.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,508
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 522
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #12
Jan 2nd, 2008
Ah, okay, got it. No, there isn't a straight-forward way to make transparent frames like that. The following article discusses a way to hack that effect though through use of screen shots:
http://www.onjava.com/pub/a/onjava/e...k41/index.html
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
  #13
Jan 2nd, 2008
Originally Posted by Ezzaral View Post
Ah, okay, got it. No, there isn't a straight-forward way to make transparent frames like that. The following article discusses a way to hack that effect though through use of screen shots:
http://www.onjava.com/pub/a/onjava/e...k41/index.html
Crap.... and its even bugy -_-....

I guess I'll just have to wait for Sun to develop one.

Anyway I'm having some trouble trying draw stuff and have components.
If want to not have the screen clear (turn gray) and display those component, how do I go about it?

So lets say I have a TextFeild, a JFrame, and a JPanel which the TextFeild goes into. I extend the JPanel and have main in it where I do the drawing with graphics. How do I go about it.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,508
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 522
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #14
Jan 2nd, 2008
Your explanation isn't very clear. Which component do you want to customize the drawing code for? Are you wanting to custom paint the background on the panel, yet not affect the text field?
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
  #15
Jan 2nd, 2008
Are you wanting to custom paint the background on the panel, yet not affect the text field?
Yip

Also I don't want the screen to be cleared every time I change the back ground. So if I change the background, the background is drawn first then the textfeild. Basicaly there's going to be an action listener that will be changing the background over an interval of time.
Last edited by Mr.UNOwen; Jan 2nd, 2008 at 7:43 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,508
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 522
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #16
Jan 2nd, 2008
If you just override paintComponent() for the JPanel, you shouldn't have any problem.
  1. new JPanel(){
  2. public void paintComponent(Graphics g){
  3. paintPanel(g);
  4. }
  5. };
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
  #17
Jan 3rd, 2008
Thanks
It even worked with paint.

The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
Last edited by Mr.UNOwen; Jan 3rd, 2008 at 12:10 am.
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
  #18
Jan 3rd, 2008
I just swiched TextField for JTextFeild and only the back ground or the Jtextfield only depending on whether I override paint (background shows) or PaintComponent(jtextFeild shows).

EDIT:

Never mind, I just had PaintComponent and not paintComponent.



The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
Last edited by Mr.UNOwen; Jan 3rd, 2008 at 12:48 am.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,508
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 522
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #19
Jan 3rd, 2008
Add your key bindings to the JFrame itself like so
  1. JRootPane root = frame.getRootPane();
  2. root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
  3. KeyStroke.getKeyStroke(KeyEvent.VK_UP,0),"UpAction");
  4.  
  5. root.getActionMap().put("UpAction",new AbstractAction(){
  6. public void actionPerformed(java.awt.event.ActionEvent e){
  7. upAction();
  8. }
  9. });
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
  #20
Jan 3rd, 2008
but how do I move from component to component, what's the method call to select and deselect a component?
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



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC