Results 1 to 4 of 4
Thread: Using Dialogs to display text
- 05-09-2011, 10:43 PM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
[SOLVED] Using Dialogs to display text
Hello,
So i've created a frame as the parent class for a dialog. This dialog is non modal. What i want to do is freely display text on the dialog at any given time. Ive tried creating built in methods but im not sure how to call them.
heres a watered down version of what im trying to do
so essentially i want to know if its possible to use dialogs in this manner and if i'm approaching the problem correctly. it seems like it isnt looking at the class when im directly calling a method from it and rather its looking at the super class that it extends.Java Code:public class progView extends FrameView { public progView(SingleFrameApplication app) { super(app); initComponents(); getFrame().setDefaultCloseOperation(3); etc etc showDebug(); //intialise the dialog with text area [b] debugWindow.debugPanelAppendText("test"); //this line does not work - debugWindow is a local dialog variable[/b] [i] the error output: cannot find symbol. location: class javax.swing.jdialog[/i] } private void showDebug() { if (debugWindow == null) { JFrame mainFrame = ProgApp.getApplication().getMainFrame(); debugWindow = new debugPanel(mainFrame,false); debugWindow.setLocationRelativeTo(mainFrame); } ProgApp.getApplication().show(debugWindow); } } public class debugPanel extends javax.swing.JDialog { /** Creates new form debugPanel */ public debugPanel(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } protected void debugPanelAppendText(String text) { debugPanelTextArea.append(text); debugPanelTextArea.append("\n"); } }
well anyway looking forward to some input
thanksLast edited by tipz; 05-10-2011 at 07:32 AM.
-
You'll need a reference to the other class in order to change its behavior (here the text it displays). To do this, the one class that is changing the behavior to the second class will need an instance field to the second class (your dialog) and then call its public methods as needed. It could possibly create the instance from within it and then display it or it could get a reference to the dialog object via a constructor or method (setter method) parameter.
So for example, the first way:
Java Code:public class ProgView { private DebugWindow myDebugWindow; public ProgView() { myDebugWindow = new DebugWindow(); // code to display the DebugWindow } public void otherMethod() { myDebugWindow.debugPanelAppendText("fubars rule!"); } }
And then the other way:
Java Code:public class ProgView { private DebugWindow myDebugWindow; public ProgView(DebugWindow myDebugWindow) { this.myDebugWindow = myDebugWindow; // don't need to call methods to display the DebugWindow as // it likely has been called by the method calling this constructor } public void otherMethod() { myDebugWindow.debugPanelAppendText("fubars rule!"); } }
Also, please follow Java coding conventions and start class names with an upper case letter. Doing this will make your coee easier for others (like us!) to understand.
- 05-10-2011, 07:31 AM #3
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
omg thankyou for the quick reply.
wow thats all i needed to solve my problem, so simple!!!! sorry im more of a c++ coder but yeah all of the classes are capitalized its just in that example i was changing a few names to make it easier to read lol big thankyou again, not very familiar with java guis.
-
Similar Threads
-
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
Display only certain contents of text file and edit display
By blkshrk81 in forum New To JavaReplies: 1Last Post: 12-01-2010, 06:35 PM -
How display text in listbox or text area right to left or center??
By sameer22 in forum CLDC and MIDPReplies: 0Last Post: 09-28-2010, 09:52 AM -
What is the different between Text format display on web browser and display on midle
By Basit781 in forum CLDC and MIDPReplies: 1Last Post: 05-31-2010, 08:46 AM -
How do I get all dialogs?
By zenteo in forum AWT / SwingReplies: 6Last Post: 03-08-2010, 10:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks