Hello,
I'm new to graphics programming and having some trouble adding a button
on-the-fly. I have created an example of my current code below. THere
is a class "TestExtends" that I would like to create and add a button
to it's parent 'WebRezProAppletForm'.
Can someone please inform me of the best way to perform this operation
using the method "addJButton" in "TestExtends" class. I'm assuming that
somehow you can get access to the frame, panel or whatever to do
this...
package com.webrezpro.app;
import com.webrezpro.lib.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class TestExtends extends WebRezProAppletForm{
/** Creates a new instance of TestExtends */
public TestExtends() {
}
public static void main(String[] args) {
TestExtends applet = new TestExtends();
applet.setStandAlone();
JFrame frame = new JFrame("WebRezPro - Frame");
frame.setSize(300,300);
frame.getContentPane().add(applet);
frame.setVisible(true);
applet.init();
applet.start();
applet.setInstructions("BEFORE ADD BUTTON");
applet.addJButton();
}
public void addJButton(){
//Some code here to add a JButton to the SOUTH of the content
Pane
}
}
package com.webrezpro.lib;
/**
*
* @author Administrator
*/
public class WebRezProAppletForm extends java.applet.Applet {
// Just add this so you don't set a warning when compiling.
public static final long serialVersionUID = 1L;
private boolean isStandAlone;
/** Initializes the applet WebRezProApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
textInstructions = new javax.swing.JTextArea();
setLayout(new java.awt.BorderLayout());
textInstructions.setColumns(80);
textInstructions.setFont(new java.awt.Font("Arial", 0, 12));
textInstructions.setLineWrap(true);
textInstructions.setRows(15);
textInstructions.setWrapStyleWord(true);
textInstructions.setBorder(new
javax.swing.border.TitledBorder("Web Rez Pro"));
add(textInstructions, java.awt.BorderLayout.CENTER);
textInstructions.getAccessibleContext().setAccessibleName("textInstructions");
}
// Variables declaration - do not modify
private javax.swing.JTextArea textInstructions;
// End of variables declaration
public boolean flagStandAlone(){
return this.isStandAlone;
}
public String getInstructions(){
return this.textInstructions.getText();
}
public void setInstructions(String instructions){
this.textInstructions.setText(instructions);
}
public void setStandAlone(){
this.isStandAlone = true;
}
}
blaine@worldweb.com - 28 Jun 2005 20:14 GMT
I found the solution... Posted below in someone is interested..
public void addJButton(){
//Some code here to add a JButton to the SOUTH of the content
Pane
JButton jbtNext = new JButton("Processing...");
jbtNext.setEnabled(false);
this.add(jbtNext,BorderLayout.SOUTH);
this.repaint();
//Register Listener
//jbtNext.addActionListener(this);
}
Andrew Thompson - 28 Jun 2005 20:32 GMT
> I found the solution... Posted below in someone is interested..
>
[quoted text clipped - 6 lines]
> this.add(jbtNext,BorderLayout.SOUTH);
> this.repaint();
//this.repaint();
validate(); // better..
Note: Follow-Ups set to c.l.j.help only

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane