Alternative for deprecated method JFrame.show()  
Author Message
Mike





PostPosted: 2006-1-5 2:03:00 Top

java-programmer, Alternative for deprecated method JFrame.show() I'm messing around with Java Swing. I'm also messing around with
Eclipse instead of a plain text editor such as TextPad.

When I create the following two classes in Eclipse, I get a persistent
warning that

The method show() from the type Window is deprecated

But I've checked the API docs (hence my looking for the 1.5.0 docs) and
it does NOT indicate that show() is deprecated. Any words of
guidance/advice?

Thanks

import javax.swing.*;

public class LoanCalculatorApp
{
public static void main(String[] args)
{
JFrame frame = new LoanCalculatorFrame();
frame.show();
}
}


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;


public class LoanCalculatorFrame extends JFrame
{
public LoanCalculatorFrame()
{
setTitle("Loan Calculator");
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
System.out.println("Screen:" + d.width + " by " + d.height + "
pixels");
int height = 200;
int width = 267;
setBounds((d.width-width)/2, (d.height-height)/2, width, height);
setResizable(false);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
JPanel panel = new JPanel();
contentPane.add(panel);

}
}

 
jlp





PostPosted: 2006-1-5 2:27:00 Top

java-programmer >> Alternative for deprecated method JFrame.show() Mike a 閏rit :
> I'm messing around with Java Swing. I'm also messing around with
> Eclipse instead of a plain text editor such as TextPad.
>
> When I create the following two classes in Eclipse, I get a persistent
> warning that
>
> The method show() from the type Window is deprecated
>
> But I've checked the API docs (hence my looking for the 1.5.0 docs) and
> it does NOT indicate that show() is deprecated. Any words of
> guidance/advice?
>
> Thanks
>
> import javax.swing.*;
>
> public class LoanCalculatorApp
> {
> public static void main(String[] args)
> {
> JFrame frame = new LoanCalculatorFrame();
> frame.show();
> }
> }
>
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import java.text.*;
>
>
> public class LoanCalculatorFrame extends JFrame
> {
> public LoanCalculatorFrame()
> {
> setTitle("Loan Calculator");
> Toolkit tk = Toolkit.getDefaultToolkit();
> Dimension d = tk.getScreenSize();
> System.out.println("Screen:" + d.width + " by " + d.height + "
> pixels");
> int height = 200;
> int width = 267;
> setBounds((d.width-width)/2, (d.height-height)/2, width, height);
> setResizable(false);
> addWindowListener(new WindowAdapter()
> {
> public void windowClosing(WindowEvent e)
> {
> System.exit(0);
> }
> });
> Container contentPane = getContentPane();
> JPanel panel = new JPanel();
> contentPane.add(panel);
>
> }
> }
>
in Swing components .show() is replaced by .setVisible(true) or
.setVisible(false).
to show or hide the component.

 
IchBin





PostPosted: 2006-1-5 2:27:00 Top

java-programmer >> Alternative for deprecated method JFrame.show() Mike wrote:
> I'm messing around with Java Swing. I'm also messing around with
> Eclipse instead of a plain text editor such as TextPad.
>
> When I create the following two classes in Eclipse, I get a persistent
> warning that
>
> The method show() from the type Window is deprecated
>
> But I've checked the API docs (hence my looking for the 1.5.0 docs) and
> it does NOT indicate that show() is deprecated. Any words of
> guidance/advice?
>
> Thanks
>
> import javax.swing.*;
>
> public class LoanCalculatorApp
> {
> public static void main(String[] args)
> {
> JFrame frame = new LoanCalculatorFrame();
> frame.show();
> }
> }
>
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import java.text.*;
>
>
> public class LoanCalculatorFrame extends JFrame
> {
> public LoanCalculatorFrame()
> {
> setTitle("Loan Calculator");
> Toolkit tk = Toolkit.getDefaultToolkit();
> Dimension d = tk.getScreenSize();
> System.out.println("Screen:" + d.width + " by " + d.height + "
> pixels");
> int height = 200;
> int width = 267;
> setBounds((d.width-width)/2, (d.height-height)/2, width, height);
> setResizable(false);
> addWindowListener(new WindowAdapter()
> {
> public void windowClosing(WindowEvent e)
> {
> System.exit(0);
> }
> });
> Container contentPane = getContentPane();
> JPanel panel = new JPanel();
> contentPane.add(panel);
>
> }
> }
>
It has been deprecated for long time now. Not sure why it is not marked
as deprecated in 1.5...

Use frame.setVisible(true)

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
 
Steve W. Jackson





PostPosted: 2006-1-5 2:48:00 Top

java-programmer >> Alternative for deprecated method JFrame.show() In article <email***@***.com>, IchBin <email***@***.com>
wrote:

> Mike wrote:
> > I'm messing around with Java Swing. I'm also messing around with
> > Eclipse instead of a plain text editor such as TextPad.
> >
> > When I create the following two classes in Eclipse, I get a persistent
> > warning that
> >
> > The method show() from the type Window is deprecated
> >
> > But I've checked the API docs (hence my looking for the 1.5.0 docs) and
> > it does NOT indicate that show() is deprecated. Any words of
> > guidance/advice?
> >
> > Thanks
> >

[ snip ]

> >
> It has been deprecated for long time now. Not sure why it is not marked
> as deprecated in 1.5...
>
> Use frame.setVisible(true)

The show method of Component has been deprecated since Java 1.1. The
show method of Window (inherited by Dialog/JDialog and Frame/JFrame) is
deprecated as of 1.5. Personally, I find that confusing. When dealing
with a window, I find it eminently more meaningful to use show/hide
calls. But that's just me...

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
 
 
Mike





PostPosted: 2006-1-5 3:54:00 Top

java-programmer >> Alternative for deprecated method JFrame.show() Again, thanks to all. Your help is always much appreciated.

 
 
Chris Smith





PostPosted: 2006-1-5 5:01:00 Top

java-programmer >> Alternative for deprecated method JFrame.show() jlp <jlp@com> wrote:
> in Swing components .show() is replaced by .setVisible(true) or
> .setVisible(false).
> to show or hide the component.

Well, this really has nothing at all to do with Swing. It's true of all
AWT components, lightweight or not.

It was initially a change in Java 1.1 to bring AWT in line with the
JavaBeans spec... for some time, the Window classes still were not
subject to the deprecation, but someone finally decided to change than
in Java 1.5.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation