Trouble adding actionlistener to a panel in a tabbed pane
Hi, please help me! this is the code i wrote, with the error given below:
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tabslisten extends JApplet
JPanel RecPanel;
GridBagLayout gbl;
GridBagConstraints gbc;
public void init ()
FlowLayout flow;
flow = new FlowLayout();
Container content = getContentPane();
content.setLayout(new GridLayout());
JTabbedPane tabpane = new JTabbedPane();
content.add(tabpane, flow);
RecPanel = new JPanel();
recipientDetails();
tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");
public void recipientDetails()
JLabel lblRecFName;
JLabel lblRecLName;
JTextField txtRecFName;
JTextField txtRecLName;
JButton btnValidate;
gbl = new GridBagLayout();
gbc = new GridBagConstraints();
RecPanel.setLayout(gbl);
lblRecFName = new JLabel("First Name");
lblRecLName = new JLabel("Last Name");
txtRecFName = new JTextField(8);
txtRecLName = new JTextField(5);
btnValidate= new JButton("Validate");
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbl.setConstraints(lblRecFName, gbc);
RecPanel.add(lblRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbl.setConstraints(txtRecFName, gbc);
RecPanel.add(txtRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbl.setConstraints(lblRecLName, gbc);
RecPanel.add(lblRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbl.setConstraints(txtRecLName, gbc);
RecPanel.add(txtRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 32;
gbl.setConstraints(btnValidate, gbc);
RecPanel.add(btnValidate);
validateAction validateButton = new validateAction();
btnValidate.addActionListener(validateButton);
class validateAction implements ActionListener
public void actionPerformed(ActionEvent evt)
Object obj = evt.getSource();
if (obj == btnValidate)
String fName = txtRecFName.getText();
String lName = txtRecLName.getText();
if (fName.length()==0)
getAppletContext().showStatus("First Name not entered.");
return;
else if (lName.length()==0)
getAppletContext().showStatus("Last Name not entered.");
return;
else
getAppletContext().showStatus("Successful.");
ERROR:
tabslisten.java:90: Undefined variable: btnValidate
if (obj == btnValidate)
^
tabslisten.java:92: Undefined variable or class name: txtRecFName
String fName = txtRecFName.getText();
^
tabslisten.java:93: Undefined variable or class name: txtRecLName
String lName = txtRecLName.getText();
^
3 errors
Press any key to continue...
I'm sure I'm doing something really stupid, but I don't know what! ANY and ALL help will be appreciated! Thanks!
I copied your program and ran it. It works fine. Make sure the three variables you made class variables are only defined in one place. (ie you moved them not copied them). Other than that I have no ideas.
With regards to naming conventions. My only comment is, take a look at the Java API.
1) classes have uppercased words. Examples from your program - JTextField, Container, FlowLayout, GridLayout...
2) methods and variable names don't upper case the first word - getContentPane(), setLayout()...
Here is the program that works for me:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FirstApplet extends JApplet
JPanel RecPanel;
GridBagLayout gbl;
GridBagConstraints gbc;
JTextField txtRecFName;
JTextField txtRecLName;
JButton btnValidate;
public void init ()
System.out.println("hello there");
FlowLayout flow;
flow = new FlowLayout();
Container content = getContentPane();
content.setLayout(new GridLayout());
JTabbedPane tabpane = new JTabbedPane();
content.add(tabpane, flow);
RecPanel = new JPanel();
recipientDetails();
tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");
public void recipientDetails()
JLabel lblRecFName;
JLabel lblRecLName;
gbl = new GridBagLayout();
gbc = new GridBagConstraints();
RecPanel.setLayout(gbl);
lblRecFName = new JLabel("First Name");
lblRecLName = new JLabel("Last Name");
txtRecFName = new JTextField(8);
txtRecLName = new JTextField(5);
btnValidate= new JButton("Validate");
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gbl.setConstraints(lblRecFName, gbc);
RecPanel.add(lblRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gbl.setConstraints(txtRecFName, gbc);
RecPanel.add(txtRecFName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gbl.setConstraints(lblRecLName, gbc);
RecPanel.add(lblRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gbl.setConstraints(txtRecLName, gbc);
RecPanel.add(txtRecLName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 32;
gbl.setConstraints(btnValidate, gbc);
RecPanel.add(btnValidate);
validateAction validateButton = new validateAction();
btnValidate.addActionListener(validateButton);
class validateAction implements ActionListener
public void actionPerformed(ActionEvent evt)
Object obj = evt.getSource();
if (obj == btnValidate)
String fName = txtRecFName.getText();
String lName = txtRecLName.getText();
if (fName.length()==0)
getAppletContext().showStatus("First Name not entered.");
return;
else if (lName.length()==0)
getAppletContext().showStatus("Last Name not entered.");
return;
else
getAppletContext().showStatus("Successful.");
Similar Messages
-
How to a particular panel in a tabbed pane to the front?
Hello
I have a small application that uses a tabbed pane. At some point I want to press a button in one of the panels of the tabbed pane and then another panel in the same tabbed pane to show up, as if I had clicked on that tab to bring it to the front.
Only difference is I don't want to click on the tab to do it but on another button, so I can do some more stuff through the button before I bring the other panel to the front
I thought I could do this by getting focus, but it seems not to be the case. Getting focus does not mean coming to the front as I originally thought.
I hope this is clear. Here is an example that you can compile and run. I want to get jpanel2 to the front by clicking jbutton1 and vice versa.
Any help appreciated.
(Frame1.java)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
private JTabbedPane jTabbedPane1 = new JTabbedPane();
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
public Frame1() {
try {
jbInit();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
} catch (Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize( new Dimension(400, 300) );
jTabbedPane1.setBounds(new Rectangle(0, 0, 395, 270));
jPanel1.setLayout(null);
jPanel2.setLayout(null);
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(20, 170, 160, 25));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
jButton2.setText("jButton2");
jButton2.setBounds(new Rectangle(20, 135, 160, 25));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
jTextField1.setBounds(new Rectangle(55, 45, 210, 20));
jTextField2.setBounds(new Rectangle(95, 50, 180, 20));
jPanel1.add(jTextField1, null);
jPanel1.add(jButton1, null);
jTabbedPane1.addTab("jPanel1", jPanel1);
jPanel2.add(jTextField2, null);
jPanel2.add(jButton2, null);
jTabbedPane1.addTab("jPanel2", jPanel2);
this.getContentPane().add(jTabbedPane1, null);
private void jButton1_actionPerformed(ActionEvent e) {
private void jButton2_actionPerformed(ActionEvent e) {
public static void main(String[] args) {
new Frame1();
}tabbedPane.setSelectedIndex(...);
-
hi everybody!
how can insert several panel into a tabbed pane ???
thankshi,
i mean into a tab of tabbedpane!!
haleh -
New Zen trouble adding a memory card (not seen)?
0New Zen trouble adding a memory card (not seen)?8I have a new zen 4gb unit and love it, saw it has a memory card slot so i stuck an 8gb sdhc sandisk 3 extreme memory card in there, figured I could dump more fun stuff in there on it but when i use the zen explorer i don't see that card.
I formatted the sdhc card in fat 32 and named it sd4zen yet when its in the zen and i check my computer I am not seeing the card in the windows menus to drag stuff over onto for the zen nor is it showing in any of the zen media explorer areas.
Do i need to dump stuff onto the memory card externally (thru a card reader first) then insert it and access that thru the memory part of the zen menu, or are the zens not able to read from an sdhc sd card or is 8 gb too big (compatability)?
Thanks for any help on this,
BillI am a dork, a few mins messing with it i realized in the main menu of the zen with the card inserted hit removable disk and hook up via usb, now my computer sees the sd4zen dri've and i can dump more fun stuff for zen on there...
Sorry to take up space maybe someone will read this and help them with the same issue i was having or mods if you choose just delete.
Bill -
Trouble adding comments using Reader X from enabled comments in Acrobat 9
I am a Technical Writer with Acrobat 9. Regularly I make my documents comment enabled for reader. IT has been updating systems and some of my recipients now have Reader X. Because of the difficulty they have, when they open the commentable PDF they are having trouble adding comments and wind up printing the document, marking up the hard copy, scanning it and emailing it back. What am I doing wrong? Is Reader X not downward compatible? We want to move forward with technology, not backwards.
Right click the document opened in Reader X and then click "Select Tool".
Hope that helps.
Thanks,
Abhilasha -
I am having trouble adding appointments to my various calendars. No probems before ios7 update. What am I doing wrong??
iPhone 3G IOS 4.2.1 is the latest & greatest. There's no more updates for this iPhone.
You have to buy a new iPhone since most apps target IOS 6 & IOS 7. -
Having trouble adding purchased and imported music to my playlists
I'm having trouble adding purchased and imported music to my play lists. For example when I purchase or import new music to my playlists I have to re sync my ipod or the new songs don't appear on my playlists. Perhaps this is because I once unplugged my ipod w/out first disconnecting it. Previously when I purchased and imported music songs would appear on my play lists when I dragged them from purchased to playlist.
Remember to authorise your new machine with the Apple ID
Essentially copy the itunes folder and all sub folders over to the same place in the new computer.
Windows XP: C:\Documents and Settings\username\My Documents\My Music\iTunes\
Windows Vista: C:\Users\username\Music\iTunes\
Windows 7: C:\Users\username\My Music\iTunes\
Windows 8: C:\Users\username\My Music\iTunes\ -
Hello, I am having Trouble adding Audiobooks in iTunes 12.1.2.27 with OSX Yosemite 10.10.3, I downloaded 4 Audiobooks from Audible, Synced my iPod but the new Audiobooks do not show up in either the Audiobooks or Music section of my iPod after I sync my iPod, I do see them in the Audio section of iTunes but not on my iPod, any help would be greatly appreciated. thank you Michael
Hello, I am having Trouble adding Audiobooks in iTunes 12.1.2.27 with OSX Yosemite 10.10.3, I downloaded 4 Audiobooks from Audible, Synced my iPod but the new Audiobooks do not show up in either the Audiobooks or Music section of my iPod after I sync my iPod, I do see them in the Audio section of iTunes but not on my iPod, any help would be greatly appreciated. thank you Michael
-
Added actionListener, then GUI broke
Hi,
1. first i ran my menu GUI, it worked fine
2. then i added the actionListener code... now she no workie...
what did i do wrong???
ERROR MSG:
C:\jLotto\LotFrame.java:34: cannot resolve symbol
symbol : class ActionListener
location: class LottoFrame
new ActionListener(){
^
1 error
Tool completed with exit code 1
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import java.awt.Event;
import javax.swing.JOptionPane; //print menu trial run
public class LotFrame extends JFrame
// Constructor
public LotFrame(String title)
setTitle(title); // Set the window title
setDefaultCloseOperation(EXIT_ON_CLOSE); // handle exit operation
setJMenuBar(menuBar); // Add the menu bar to the window
//MAIN MENU
JMenu fileMenu = new JMenu("File"); // Create File menu
JMenu findMenu = new JMenu("Find");
// Construct the file pull down menu
newItem = fileMenu.add("New"); // Add New item
openItem = fileMenu.add("Open"); // Add Open item
closeItem = fileMenu.add("Close"); // Add Close item
fileMenu.addSeparator(); // Add separator
saveItem = fileMenu.add("Save"); // Add Save item
saveAsItem= fileMenu.add("Save As..."); // Add Save As item
fileMenu.addSeparator(); // Add separator
printItem.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent e )
JOptionPane.showMessageDialog( LotFrame.this,
"adding actionListener at end of GUI setup",
"action at end", JOptionPane.PLAIN_MESSAGE);
}//end of actionPerformed
}//end of actionLinstener
);//endof .addActionListener
printItem = fileMenu.add("Print"); // Add Print item
menuBar.add(fileMenu); // Add the file menu
menuBar.add(findMenu);
}//end of constructor
private JMenuBar menuBar = new JMenuBar(); // Window menu bar
// File menu items
private JMenuItem newItem, openItem, closeItem, saveItem, saveAsItem, printItem;
}//end of class LotFramejava.awt.event.*;
import java.awt.Event; -
I am having Trouble adding Audiobooks in iTunes 12
Hello, I am having Trouble adding Audiobooks in iTunes 12.1.2.27 with OSX Yosemite 10.10.3, I downloaded 4 Audiobooks from Audible, Synced my iPod but the new Audiobooks do not show up in either the Audiobooks or Music section of my iPod after I sync my iPod, I do see them in the Audio section of iTunes but not on my iPod, any help would be greatly appreciated. thank you Michael
I do have an icon of my iPod but if I click on it it disconnects my iPod from iTunes.
If the iPod is connected via Wi-Fi, please connect with USB. If it's already on USB, or if USB is the same. log out or restart the computer and also restart the iPod, then try again. If it still doesn't work, see below.
Launch the Console application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ Open LaunchPad and start typing the name.
The title of the Console window should be All Messages. If it isn't, select
SYSTEM LOG QUERIES ▹ All Messages
from the log list on the left. If you don't see that list, select
View ▹ Show Log List
from the menu bar at the top of the screen.
Click the Clear Display icon in the toolbar. Then take the action that isn't working the way you expect. Select any lines that appear in the Console window. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
The log contains a vast amount of information, almost all of which is irrelevant to solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
Please don't indiscriminately dump thousands of lines from the log into this discussion.
Please don't post screenshots of log messages—post the text.
Some private information, such as your name or email address, may appear in the log. Anonymize before posting.
When you post the log extract, you might see an error message on the web page: "You have included content in your post that is not permitted," or "The message contains invalid characters." That's a bug in the forum software. Please post the text on Pastebin, then post a link here to the page you created. -
I am having trouble adding art work for itunes 12.0.1.26
I am having trouble adding art work for itunes 12.0.1.26. Trying to add artwork after you go into "get info" and then "add artwork" doesn't work. Can anyone help. BTW, went into the authorization edit and gave my user id permission to modify things as was suggested in one posting, but that didn't work either.
thanks a lot
-
Trouble adding GoodSearch HTML search box: HTML widget doesn't work...
I'm having trouble adding a GoodSearch search engine box to my site. I've tried the HTML widget thing and also editing the code after it publishes to a folder. Each time, I get a non-functional search box as my end result.
The GoodSearch tech person says that iWeb might be stripping out or corrupting the Javascript code...interestingly enough, a Google search box works just fine with post code tweaking.
Any help would be greatly appreciated!
Here is a link to my test site where the search box (upper right corner) is non-functional: http://web.mac.com/toesproductions/KQ/Home.html
This is the GoodSearch code:
<script type="text/javascript">
function GoGoodSearch_4()
var charityid = 870537;
var siteURL = "koreanquarterly.org/home.html";
var openNewWindow = true;
var searchtype = document.getElementsByName("goodsearchsearchtype4");
var baseurl = "http://www.goodsearch.com/Search.aspx";
var keywordsbox = document.getElementById("goodsearchkeywords4");
if (typeof keywordsbox != "undefined")
var keywords = escape(keywordsbox.value);
var url = baseurl + "?Keywords=" + keywords;
if (charityid > 0)
url += "&CharityID=" + charityid;
if (searchtype[1].checked)
url += "&Site=" + escape(siteURL);
url += "&Partner=goodsearch_syn";
url += "&typetag=" + escape(siteURL);
if (openNewWindow)
window.open(url,'SearchResults','height=700,width=900,location=1,status=1,toolba
r=1,scrollbars=1,resizable=1');
else
window.location.href = url;
function CatchEnter_4(e)
var key1 = "13";
var x = "";
if (document.all)
var evnt = window.event;
x = evnt.keyCode;
else
x = e.keyCode;
if (x == key1)
document.getElementById("goodsearchsubmit4").click();
return false;
else
return true;
</script>
<label for="goodsearchkeywords4" style="display:none;">GoodSearch keywords to
search for</label>
<input
type="text"
name="goodsearchkeywords4"
id="goodsearchkeywords4"
onkeydown="return CatchEnter_4(event);"
style="width:230px;background-image:url('http://www.goodsearch.com/gfx/titleya
hoo_background.gif');background-repeat:no-repeat;margin-bottom:8px;"
onclick="this.style.backgroundImage='url(http://www.goodsearch.com/_gfx/spacer.g
if)';"
onfocus="this.style.backgroundImage='url(http://www.goodsearch.com/_gfx/spacer.g
if)';"
/>
<input
type="button"
name="goodsearchsubmit4"
id="goodsearchsubmit4"
value="Search"
onclick="GoGoodSearch_4();"
style="margin-bottom:8px;font-family:Arial,Helvetica;font-size:11px;"
/>
<input
type="radio"
name="goodsearchsearchtype4"
value="web"
/> Web
<input
type="radio"
name="goodsearchsearchtype4"
value="site"
/> This Site
Message was edited by: Andrea LeeiWeb does nothing to code you add in the HTML Snippet.
Actually, iWeb does not care what you put there. It blindly saves the code in a webpage.
http://web.mac.com/toesproductions/KQ//Homefiles/widget0markup.html
So, now you have no excuse.
Just edit the code in the file above until it works.
After that, copy the code in the BODY of the page and paste in into the HTML Snippet. Otherwise it will overwrite the webpage next time you publish. -
Adding actionListener to JComboBox
Hi there
I have added actionListener to a JComboBox. I only want the actionPerformed() get called when the user choose the item in the JComboBox, however, it also get called whenever I change the items in the JComboBox.
I have tried to call the ActionEvent.getID() method to identify the action, however, changing the items and choosing the item give me the same ID - 1001.
Has anyone got this problem before? How did you solve it?
Should I use other Listener for listening only the choosing event?
In advance thanks!
From
EdmondI had many problems using actionListeners with JComboBox because it gets called all the time, I have had much better luck using mouseListener and the events getClickCount() method for single and double click selections, this avoided many of the problems for me.
-
I am trying to switch from IE8 to Firefox but am having trouble adding all of the toolbars I use daily to Firefox. I want to add CouponBar from Coupons.com, Roboform (which it said was added, but is not showing up), Adobe Contribute CS3, and Canon Easy-Web Print EX (for my Canon MX340 printer). Please advise!
For Roboform you can install the adapter for Firefox from here.
http://www.roboform.com/browsers.html
You want the one under '''Firefox, Mozilla and Netscape'''.
Browser Version XPI file to use if not installed automatically
'''Firefox 3.0 - 3.7a1pre ''Installed Automatically (roboform-firefox-3.0-frozen.xpi)'''''
Or, you can install it with this link:
http://www.roboform.com/dist/roboform-firefox-3.0-frozen.xpi
As far as the other three programs you mentioned, check the websites for those programs to see if they even have a toolbar that is made for Firefox. -
Trouble adding alias to the web.xml file (External Facing Portal)
I'm trying to implement the external facing portal. I don't really have any real custom content to add to it but have just created an iView that contains a webpage that's contained within a copy of the light framework.
I'm having trouble adding or accessing the alias that I've created to go to this iView.
I can test my iView by adding it to the master rule collection under one of the predefined aliases in the web.xml (e.g. portal/anonymous etc) but when i define my own (e.g. "ext" etc) and then go to http://portal:<port>/irj/ext I'm just getting an error:
The requested resource does not exist.
Details: Go to main page of this application!
This is what my entry in the web.xml file looks like:
<web-app>
<display-name>The Java iView Runtime</display-name>
<listener>
<listener-class>
com.sapportals.portal.prt.session.HttpSessionHandler
</listener-class>
</listener>
<servlet>
<servlet>
<init-param>
<param-name>
portal/anonymous
</param-name>
<param-value>
anonymous=1,proxy=0,low_bandwidth=0,include_in_url=1,include_application_name_in_url=1
</param-value>
</init-param>
<init-param>
<param-name>
ext
</param-name>
<param-value>
anonymous=1,proxy=0,low_bandwidth=1,include_in_url=1,include_application_name_in_url=1
</param-value>
<init-param>
</servlet>
My master rule collection seems to be correct, since I can test the iView etc by adding it to a predefined alias. I've tried closing all browsers etc. Nothing seems to work.
Any ideas what this could be?
Thanks!
I'll award points for any help.Hi Beau
Just Have a try.
In the servlet mapping add the following entry.
<servlet-mapping>
<servlet-name> gateway </servlet-name>
<url-pattern> /portal/* </url-pattern>
</servlet-mapping>
<b><servlet-mapping>
<servlet-name> gateway </servlet-name>
<url-pattern> /ext/* </url-pattern>
</servlet-mapping></b>
<servlet-mapping>
<servlet-name> prt </servlet-name>
<url-pattern> /irj/* </url-pattern>
</servlet-mapping>
Restart after making the changes.
Regards
Geogi Luke
Maybe you are looking for
-
My sons ipod has been stolen, how can I get it back.
I have try to sent the SMS by fine my ipod, but its didn't work. Can I get my sons iPod back by see the serial number.
-
Mu external hard disk partition is not working. In get info it says that "hou can read only" bow can I fix this?
-
Mac Multiple Users - How to exclude for some users?
Hi, I have BBDM installed on a Mac with multiple users. A couple of those are children so I have Parental controls turned on, and BBDM excluded from their available list. However, when they log in BBDM is trying to sync artwork or something and cont
-
Business Objects/ePortfolio
1. Several reports are receving a Malloc Error in Crystal. 2. Several reports are receiving Database Connection error or Failed to Open Connection error when scheduled in Business Object but the reports run fine in Crystal. 3. Several reports run suc
-
Ipad un sync photos does not remove them
I have tried to delete my synced photos by unchecking the sync photo box on my mac. I have hit the remove photos box that comes after. All the photos are still on the ipad. I do not use the cloud and do not use match. I did delete the camera roll one