Sagewire Logo

Frames from an applet

2 Message(s) by 2 Author(s) originally posted in java language


From: petoeter Date:   Saturday, February 24, 2007
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), generate
different frames.
Hereby my (simpified) code. What's wrong? 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);
}
}


From: Andrew Thompson Date:   Saturday, February 24, 2007
wrote in message:
..
The aim is to ...



..post your question to every known JAVA group?
<http://groups.google.com/group/comp.lang.JAVA.programmer/
browse_thread/thread/6f73a8f7607b99a0/397f203f83748ad0?
q=applet&rnum=2#397f203f83748ad0>


Please refrain from reposting messages.

Andrew T.



Next Message: Modify JAVA interpreter?


Blogs related to Frames from an applet

Button fills up whole of the frame !! what am I doing wrong??
I am trying to open a frame from an applet and I have put a button in the frame . But , it fills up the frame window.. How can I make it.

java faqs
Ans: Window, Frame and Dialog classes use a BorderLayout as their layout. 62) Which containers use a Flow layout as their default layout? Ans: Panel and Applet classes use the FlowLayout as their default layout. ...

About Calling a Frame object In a Applet
Hi,,,,,,,, Any body tell me did I call a class object which extends a Frame into an Applet or I should stick on the Panel for.

Frames from an applet
... starting from an applet, the user can a make a choice (by radio buttons and an OK button), generate different frames. Hereby my (simpified) code. What's wrong? Thanks, (as a am a novice, all suggestions are wellcome) import java.awt ...

frames from an applet
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 ...

Moziilla fails Calling a Frame from an Applet
Hey, The applet shows a frame when actionevent occurs. It works fine with applet viewer and ie, but doesn't work with firefox. The frame just.


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional