I have a panel in a GUI that has three components: A JTextArea, a JCheckBox
and a JButton. When the button is pressed, I want to check the value of
the checkbox and get the text of the textarea and store the info in a file.
I've found that the paramString() method for components is PROTECTED, so I
can't get to it from another class.
I tried declaring the component inside the class, like this:
private class MyPanel extends JPanel implements ActionListener {
JTextArea tFeedback = new JTextArea();
private void MyPanel() {
(The text box is sized and added to the panel here, along
with other components)
JButton button = new JButton("Save info");
ActionListener aListen = new MyPanel();
button.addActio nListener(aList en);
}
private void ActionPerformed (ActionEvent event) {
String sText = tFeedback.param String();
}
}
And I can't access paramString() in the ActionPerformed method. I thought
that protected would allow access within the class, but I can't access it
from a method in the same class. I also tried NOT creating a new class for
the listener and doing this: button.addActio nListener(this) ; and it still
won't work.
I tried using an inner class and an anonymous class. There's no need to
respond to the text area, since the text isn't modified (by the program, at
least) until I get it and save it. The same with the checkbox -- I don't
need to know anything about it until the "Save" button is pressed, but any
way I try to create a listener in this class still doesn't let me access
the data in components other than the one that generated the event.
Any ideas?
Thanks!
Hal 1 5172
It seems I was misinformed by someone at a usergroup that was trying to help
me. the paramString() method is not what one uses to get information about
a component. Once I established I had the wrong info, I was able to solve
the problem quickly.
Hal
Hal Vaughan wrote: I have a panel in a GUI that has three components: A JTextArea, a JCheckBox and a JButton. When the button is pressed, I want to check the value of the checkbox and get the text of the textarea and store the info in a file. I've found that the paramString() method for components is PROTECTED, so I can't get to it from another class.
I tried declaring the component inside the class, like this:
private class MyPanel extends JPanel implements ActionListener {
JTextArea tFeedback = new JTextArea();
private void MyPanel() { (The text box is sized and added to the panel here, along with other components)
JButton button = new JButton("Save info"); ActionListener aListen = new MyPanel(); button.addActio nListener(aList en); }
private void ActionPerformed (ActionEvent event) { String sText = tFeedback.param String(); } }
And I can't access paramString() in the ActionPerformed method. I thought that protected would allow access within the class, but I can't access it from a method in the same class. I also tried NOT creating a new class for the listener and doing this: button.addActio nListener(this) ; and it still won't work.
I tried using an inner class and an anonymous class. There's no need to respond to the text area, since the text isn't modified (by the program, at least) until I get it and save it. The same with the checkbox -- I don't need to know anything about it until the "Save" button is pressed, but any way I try to create a listener in this class still doesn't let me access the data in components other than the one that generated the event.
Any ideas?
Thanks!
Hal This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joseph |
last post by:
hi
1) i plan on having an awt canvas component (to draw graphs) on a JFrame
with other swing components..will this be okay? i've read that swing and
awt aren't compatible..
2)Also, if i have a function which simply loops infinately that is part of a
form, what happens when a form event (eg button click) occurs? will the
event handler be executed simulatanesouly with the loop? or does the event
excecute first and then the loop is...
|
by: brazilnut52 |
last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better
I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to register for COM interop in Visual Studio
So I go into Excel (where I want to use the object). Go to VB...
|
by: J F |
last post by:
Hi all
I'm totally new to Visual Studio, coming from Delphi.
My question, I'm sure is pretty trivial.
I'm using C#
I have a component class (Project/Add Class/Component Class). In this
component class, I drop an ImageList.
|
by: Edward Diener |
last post by:
How does one specify in a component that a property is a pointer to another
component ? How is this different from a property that is actually an
embedded component ? Finally how is one notified in a component when another
component is destroyed ?
I have a managed component called P. Let us say that C is another managed
component. If on P I have:
__property C * get_CComp();
__property void set_CComp(C *);
|
by: Jordan Bowness |
last post by:
I make a similar post in another newsgroup, but this example is
simplified somewhat.
I have a component (cmpMyComponent) with 2 properties. The 1st property
is a string value (Description) and the 2nd property is a strongly typed
collection class (myCollectionProperty).
The collection contains a simple class (myCustomClass) which has 1 text
property (TextProperty).
| |
by: RSH |
last post by:
I havent been able to set a property from another class with out getting
some sort of error.
Can someone please tell me what I'm doing wrong here?
Public Class Form1
|
by: Steve |
last post by:
hi, i'm fairly new to java and am experimenting with various swing
components. as far as I know at this time, when a change occurs in the text
i want to display, in order to show it, I have to repaint the frame.
Is there a component or way of placing a textarea of sorts in a GUI and then
have they data fed to it update without having to refresh the whole frame
each time? for example, log files fed to the GUI... as the data comes in
each...
|
by: Nuwang |
last post by:
Hai,
I'm using a swing to connect database with swing application...
1. How this swing connect with access database...
2. Important thing is how change Button size and Font size
Still I couldn't manage my swing in proper layout pls run and check
Code:
|
by: yeshello54 |
last post by:
Hey guys i am pretty new to java swing and need some help. I am developing a simple color chooser program in swing. I have a color panel that is connected to three sliders. red green and blue. but for some reason i cant get it to work..i will post my code and if anyone has any insight to why my changelistener wont work correctly I would really appreciate it. Thanks.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |