Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

frmas from and applet

Thread view: 
petoeter - 24 Feb 2007 10:38 GMT
Hi,

The aim is to write some code so , starting from an applet, the user
can a make a choice (by radio buttons and an OK button),  to let pop
up
different frames.
Hereby my (simpified) code. What's wrong, no way to generate a frame?
Thanks,
(as a am a novice, all suggestions are wellcome)

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

public class test extends JApplet implements ItemListener {
       JRadioButton radio1;
       ButtonGroup groep;
       JButton knop;
       int a;
       public void init() {
               Container contentPane = getContentPane();
               contentPane.setLayout(new GridLayout(2,0));
               groep = new ButtonGroup();
               radio1 = new JRadioButton("test");
               groep.add(radio1);
               radio1.addItemListener(this);
               contentPane.add(radio1);
               knop = new JButton( "OK");
               contentPane.add(knop);
               knop.addActionListener(new ActionListener() {
                       public void actionPerformed (ActionEvent ev){
                                       if (a ==1) {
                                               frame1 one = new
frame1();
                                               one.frame1();
                                               }
                                       }
                       });
               }

       public void itemStateChanged(ItemEvent e) {
               if (e.getItemSelectable() == radio1){
                       a = 1;
                       }
               }
       }
class frame1 extends JFrame {
       panel j;
       public void frame1() {
               Container contentPane = getContentPane();
               j = new panel();
               contentPane.add(j);
               JTextField t;
               t = new JTextField(20);
               contentPane.add(t);
               }
       public static void main(String args[]) {
               final JFrame f = new frame1();
               f.setBounds(100, 100, 300, 300);
               f.setVisible(true);
               f.setDefaultCloseOperation(EXIT_ON_CLOSE);
               f.addWindowListener(new WindowAdapter() {
                       public void windowClosed(WindowEvent e) {
                               System.exit(0);
                               }
                       });
               }
       }
class panel extends JPanel {
       panel() {
               setBackground(Color.white);
               }
       public void paintComponent (Graphics g) {
               super.paintComponent(g);
               g.drawString("Hi !!!    :-)", 2, 60);
               }
       }
Andrew Thompson - 24 Feb 2007 11:32 GMT
> The aim is to write some code so , starting from an applet, the user
> can a make a choice (by radio buttons and an OK button),  to let pop
> up
> different frames.
> Hereby my (simpified) code. What's wrong, no way to generate a frame?

The JFrames are being constructed, but the
applet never calls frame.setVisible(true)
(or that other stuff in the main method of
the frame class).

> (as a am a novice, all suggestions are wellcome)

Applet development is for experts and fools.
Leave it aside till much (much) later.

Andrew T.
Lew - 24 Feb 2007 15:06 GMT
> Applet development is for experts and fools.
> Leave it aside till much (much) later.

I do believe that the conjunction "and" is very well advised.  It seems one
must be both at once to write applets.

Since I run on a 64b Linux with the provided Firefox browser, I cannot run
applets here at all, no matter how expertly or foolishly written, until
various third parties get over themselves. I am able to run Webstarted apps.

- Lew
Andrew Thompson - 24 Feb 2007 15:48 GMT
> > Applet development is for experts and fools.
> > Leave it aside till much (much) later.
>
> I do believe that the conjunction "and" is very well advised.  It seems one
> must be both at once to write applets.

Good point, I actually meant to put 'or'.

> Since I run on a 64b Linux with the provided Firefox browser, I cannot run
> applets here at all, no matter how expertly or foolishly written, until
> various third parties get over themselves. I am able to run Webstarted apps.

Huh!  Thanks for that.

In a conversation the other day, one of the
respondents was complaining that they preferred
applets because web start was 'not supported
on all platforms for which Java is available'
(or words to that effect).

It is good to now have the counter-point -
'neither are applets'.

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.