Questions about Applet and JFrame

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 4,483
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: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #21
Jan 3rd, 2008
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
  #22
Jan 3rd, 2008
Thanks

You sure have a lot of time to help people out with this stuff.

By the way Will an alpha based image slow me down when doing animation at 12 fps at a screen size close to the screen resolution?
Last edited by Mr.UNOwen; Jan 3rd, 2008 at 2:30 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
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: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #23
Jan 3rd, 2008
Couldn't really say on that one. You'll just have to test it and tweak if needed. A lot of factors go into FPS besides just the resolution because most apps are doing more than simply blitting an image to the screen each cycle of the animation loop.

To keep painting as lean and responsive as possible, try to keep everything that does not directly relate to rendering out of your paintComponent() code. The paint methods can be called by many other things other than your loop, so put code that updates things or performs calculation in another method if possible and just keep the minimum about of code needed to redender the component in the paintComponent() method itself.
Last edited by Ezzaral; Jan 3rd, 2008 at 2:42 pm. Reason: a bit more info on painting
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3
Reputation: ajaypatel is an unknown quantity at this point 
Solved Threads: 0
ajaypatel ajaypatel is offline Offline
Newbie Poster

Re: Questions about Applet and JFrame

 
0
  #24
Jan 7th, 2008
Hello Mr.UNOwen,

I have same problem and i need solution if u got that.

I am creating one applet and i draw one object on it but

I want a window of applet in the shape of the objct that i draw on window.
i need that window transparent such that I can draw object such that it looks as though the window is in the shape of
that object.So is there a way to get what's displayed behind the window and display it.

Thanks,
Ajay Patel
Last edited by ajaypatel; Jan 7th, 2008 at 9:11 am. Reason: set nitification
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
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: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Questions about Applet and JFrame

 
0
  #25
Jan 7th, 2008
You obviously didn't read any of the links posted about that then, or you would have your answer. There are ways to "hack" that appearance and I posted a link to one article on it, but Java doesn't generically support transparent top-level windows or non-rectangular windows.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3
Reputation: ajaypatel is an unknown quantity at this point 
Solved Threads: 0
ajaypatel ajaypatel is offline Offline
Newbie Poster

Re: Questions about Applet and JFrame

 
0
  #26
Jan 9th, 2008
Hi Ezzaral,

ya,u r right. i got one link after that post.

http://www.onjava.com/pub/a/onjava/e...ex.html?page=3

in this we take screenshot of and put it in background of our window.
and this process is continuosly work in thread.
ok it nice and some what help ful to me. but window is still not moving.

ok in one of the above post Mr.UNOwen's question was to change the shape of window.
i found one link 4 that.
plz check this.

http://www-106.ibm.com/developerwork...rary/j-iframe/

Thanking you,
Ajay Patel
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3
Reputation: ajaypatel is an unknown quantity at this point 
Solved Threads: 0
ajaypatel ajaypatel is offline Offline
Newbie Poster

Re: Questions about Applet and JFrame

 
0
  #27
Jan 9th, 2008
continue of above...post

in that example that i see the image.actaully i put it but its not work 4 me.

can u help me..i put my code here..

-----------------------------------
TransparentBackground.java
-----------------------------------

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package swingdemo;
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
*
* @author vinod
*/

public class TransparentBackground extends JComponent implements ComponentListener, WindowFocusListener,
Runnable,MouseListener {

private JFrame frame;
private Image background;
private long lastupdate = 0;
public boolean refreshRequested = true;

@Override
protected void processMouseEvent(MouseEvent e) {
JOptionPane.showMessageDialog(null, "processMouseEvent Called");
}

public TransparentBackground(JFrame frame) {
this.frame = frame;
updateBackground( );
frame.addComponentListener(this);
frame.addMouseListener(this);
frame.addWindowFocusListener(this);
new Thread(this).setPriority(Thread.MAX_PRIORITY);
new Thread(this).start( );
}



public void componentShown(ComponentEvent evt) {
// JOptionPane.showMessageDialog(null, "componentShown Data");
repaint( );
}
public void componentResized(ComponentEvent evt)
{
JOptionPane.showMessageDialog(null, "componentResized Called");
repaint( );
}
public void componentMoved(ComponentEvent evt)
{
JOptionPane.showMessageDialog(null, "componentMoved Called");
repaint( );
}
public void componentHidden(ComponentEvent evt)
{
// JOptionPane.showMessageDialog(null, "componentHidden Called");
}


public void windowGainedFocus(WindowEvent evt) { refresh( ); }
public void windowLostFocus(WindowEvent evt) { refresh( ); }


public void refresh( ) {
if(frame.isVisible( )) {
repaint( );
refreshRequested = true;
lastupdate = new Date( ).getTime( );
}
}

public void run( ) {
try {
while(true) {
Thread.sleep(250);
long now = new Date( ).getTime( );
if(refreshRequested &&
((now - lastupdate) > 1000)) {
if(frame.isVisible( )) {
Point location = frame.getLocation( );
frame.setVisible(false);
updateBackground( );
frame.setVisible(true);
frame.setLocation(location);
refresh( );
}
lastupdate = now;
refreshRequested = false;
}
}
} catch (Exception ex) {
//p(ex.toString( ));
ex.printStackTrace( );
}
}

public void updateBackground( ) {
try {
Robot rbt = new Robot( );
Toolkit tk = Toolkit.getDefaultToolkit( );
Dimension dim = tk.getScreenSize( );
background = rbt.createScreenCapture(
new Rectangle(0,0,(int)dim.getWidth( ),
(int)dim.getHeight( )));
} catch (Exception ex) {
//p(ex.toString( ));
ex.printStackTrace( );
}
}

public void paintComponent(Graphics g) {
Point pos = this.getLocationOnScreen( );
Point offset = new Point(-pos.x,-pos.y);
g.drawImage(background,offset.x,offset.y,null);
}

public void mouseClicked(MouseEvent e) {
if(e.getButton()==MouseEvent.BUTTON3)
{
JOptionPane.showMessageDialog(null, "mouseClicked Called - 3");
}
if(e.getButton()==MouseEvent.BUTTON1)
{
JOptionPane.showMessageDialog(null, "mouseClicked Called - 1");
}
throw new UnsupportedOperationException("Not supported yet.");
}

public void mousePressed(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}

public void mouseReleased(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}

public void mouseEntered(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}

public void mouseExited(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}


}



-----------------------
Trans.java
-----------------------


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package swingdemo;

import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/**
*
* @author vinod
*/
public class Trans {
public static void main(String[] args) {
JFrame frame = new JFrame("Transparent Window");
frame.setUndecorated(true);

TransparentBackground bg = new TransparentBackground(frame);
//bg.snapBackground( );
bg.setLayout(new BorderLayout( ));

JPanel panel = new JPanel( ) {
public void paintComponent(Graphics g) {
g.setColor(Color.blue);
Image img = new ImageIcon("3250.png").getImage( );
g.drawImage(img,0,0,null);
}
};

panel.setOpaque(false);

bg.add("Center",panel);

frame.getContentPane( ).add("Center",bg);
frame.pack( );
frame.setSize(200,200);
frame.setLocation(500,500);
frame.setVisible(true);
}

}

please put any one image file inplace of 3250.png and check is it working or not?

Thank you,
Ajay Patel
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