Problem in Relation to Action Listener




Small Probelm in the code below i can't get the action listener to work. I've tried using the e.getcommand method on the button also just won't pick up anything for me. Any help with this would be great

Cheers

Derek

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Create_Mail extends JPanel implements ActionListener
{
private JButton jcomp1;
private JButton b1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JTextArea jcomp6;
private JComboBox jcomp7;
private JTextField jcomp8;
private JTextField jcomp9;
private JButton jcomp10;

public Create_Mail() {
//construct preComponents
String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};

//construct components
jcomp1 = new JButton ("Save E-Mail");
b1 = new JButton ("a");
jcomp2 = new JButton ("Exit System");
jcomp3 = new JButton ("Main Menu");
jcomp4 = new JLabel (" To :");
jcomp5 = new JLabel (" Sublect :");
jcomp6 = new JTextArea (5, 5);
jcomp7 = new JComboBox (jcomp7Items);
jcomp8 = new JTextField (5);
jcomp9 = new JTextField (5);
jcomp10 = new JButton ("Calculate Size of E-Mail");

//adjust size and set layout
setPreferredSize (new Dimension (482, 488));
setLayout (null);

//add components
add (b1);
add (jcomp1);
add (jcomp2);
add (jcomp3);
add (jcomp4);
add (jcomp5);
add (jcomp6);
add (jcomp7);
add (jcomp8);
add (jcomp9);
add (jcomp10);

//set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds (35, 360, 100, 20);
jcomp2.setBounds (160, 395, 105, 20);
jcomp3.setBounds (160, 360, 100, 20);
jcomp4.setBounds (25, 30, 100, 25);
jcomp5.setBounds (25, 80, 100, 25);
jcomp6.setBounds (30, 150, 435, 165);
jcomp7.setBounds (365, 35, 95, 20);
jcomp8.setBounds (135, 85, 210, 20);
jcomp9.setBounds (135, 35, 210, 20);
jcomp10.setBounds (285, 360, 180, 20);
b1.setBounds (100, 460, 95, 20);


}

public void actionPerformed( ActionEvent e )
{

Object Target = e.getSource();

if(Target == b1)
{
//System.out.println("fgfd");
System.exit(0);
}

}

public static void main (String[] args)
{
JFrame frame = new JFrame ("Create_Mail");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
System.out.println("fgfd");
frame.getContentPane().add (new Create_Mail());
frame.pack();
frame.setVisible (true);
}

}
Posted On: Tuesday 23rd of October 2012 10:51:39 PM Total Views:  51
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




tree refresh problem in TreeTable

I have a TreeTable struture with Tree in the first column. Tree is contructed dynamically by reading data from the GPS device. Each node(row) in the Tree represents GPS message. If i expand tree root node when the tree contruction process is going on, then there is a problem. Tree doesn't display nodes(GPS DATA) constructed/read after this point. It displays only those noded that were constructed before tree expansion. I think there is some problem with Tree refresh. Ideally it should display all the nodes that are added to the root node. I am not able to make out whether it is the problem with TreeExpansionlistener or Tree Refresh. I tried using repaint(), but it doesn't work. Please suggest me something.
VIEWS ON THIS POST

26

Posted on:

Monday 22nd October 2012
View Replies!

creating small button problem

pls, how do i design a small button using JButton
VIEWS ON THIS POST

64

Posted on:

Monday 22nd October 2012
View Replies!

problem with actionEvent command

Respected in following code what is the problem with code it is compiling fine but when i m pressing on submit button it is throwing lot of exception although i think that exception is throwing at the time when i m creating file with command RandomAccessFile. pls solve the problem import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.awt.*; import java.io.*; import java.util.*; /* */ public class first1 extends JApplet implements ActionListener{ Container con; JLabel lbl1=new JLabel("Student name"); JLabel lbl2=new JLabel("Password"); JLabel lbl3=new JLabel("Course"); JLabel lbl4=new JLabel("Subject"); JTextField txt1=new JTextField(); JTextField txt2=new JTextField(); JTextField txt3=new JTextField(); JTextField txt4=new JTextField(); JButton btn=new JButton("Submit"); public void init(){ con=getContentPane(); con.setLayout(null); lbl1.setBounds(30,30,90,40); txt1.setBounds(120,40,90,20); lbl2.setBounds(230,30,90,40); txt2.setBounds(320,40,90,20); lbl3.setBounds(30,60,90,40); txt3.setBounds(120,70,90,20); lbl4.setBounds(230,60,90,40); txt4.setBounds(320,70,90,20); btn.setBounds(200,100,90,30); con.add(txt1); con.add(txt2); con.add(txt3); con.add(txt4); con.add(lbl1); con.add(lbl2); con.add(lbl3); con.add(lbl4); con.add(btn); btn.addActionListener(this); } public void actionPerformed(ActionEvent ae){ String st1=txt1.getText(); String st2=txt2.getText(); String st3=txt3.getText(); String st4=txt4.getText(); String st=ae.getActionCommand(); try{ if("Submit".equals(st)) { RandomAccessFile raf1=new RandomAccessFile("work.txt","rw"); } } catch(IOException ie){} } }
VIEWS ON THIS POST

33

Posted on:

Monday 22nd October 2012
View Replies!

Window fixed size problem

I have to make a screen of fixed size. Means if the user drags the frame then also it should come back to its normal size. I am able to make the frame of fixed size by doing public void componentResized(ComponentEvent e) { if( (this.getHeight() < this.DIALOG_HEIGHT) || (this.getWidth() < this.DIALOG_WIDTH) || (this.getHeight() > this.DIALOG_HEIGHT) || (this.getWidth() > this.DIALOG_WIDTH) ) { this.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); } } } where DIALOG_WIDTH, DIALOG_HEIGHT are deed fixed sizes. I am using gridbag layout to arrange the components in the Frame. Whenever i drag the screen, due to the above code it is coming to the defined DIALOG_WIDTH, DIALOG_HEIGHT size, but the components are loosing their place. Any solution for this \t
VIEWS ON THIS POST

37

Posted on:

Monday 22nd October 2012
View Replies!

full-screen gray window problem and event handling problem

I want to show a fullscreen color and draw some lines. The program should work on Windows _and_ OS X. So I can not just set the window to the screen size. This will work on Windows, but not on OS X where the menu bar and dock will still be visible. I came up with the following little program which compiles fine, but shows a gray window shortly after the correct blue window is painted. Also the event handling will not work and I don't see an error. Pressing SPACE should exit the program, but doesn't. Looking forward any pointers. Here's the sample source: // ------- source full-screen begin -------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FullScreen implements KeyListener { public void keyTyped(KeyEvent event) {} public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_SPACE) { System.exit(0); } } public void go() { JWindow window = new JWindow(); window.setVisible(true); window.addKeyListener(this); window.setBackground(Color.BLUE); window.setForeground(Color.WHITE); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(window); } public void paint (Graphics g) { g.setColor(Color.WHITE); g.drawString(", World!", 50, 50); g.drawLine(0, 1000, 500, 0); } public static void main(String[] args) { FullScreen f = new FullScreen(); f.go(); } } //-------- source end -------------
VIEWS ON THIS POST

78

Posted on:

Monday 22nd October 2012
View Replies!

JTable focus problem

My JFrame has many swing components and I have set Focus traversal policy. When I press tab focus goes to next component, but when the component is table the focus gets toggled in table itself. I have to press control+tab to get out of table. But I want only tab to get out of table. Any help...
VIEWS ON THIS POST

68

Posted on:

Monday 22nd October 2012
View Replies!

background problem

Hi , I want to put an image to the background of my tab(panel) in the TabbedPane, but I do not know how to do it. So how can I do this
VIEWS ON THIS POST

72

Posted on:

Tuesday 23rd October 2012
View Replies!

Jlist listener problem

Hi all, I have a strange problem I am unable to solve in my Jlist. I am posting the code below. Please , if anyone can help, try to catch the bug. The program takes a phrase of keywords and searches them in a prestored list. It displays the results in a JList. The user can double click an item in the JList and a window would pop-up showing the respective document. There are two scenarios when I do not want the item in the list to pop-up. Those two scenarios are : a) When the user has'nt entered any keyword, the JList displays "Please enter a search phrase with each word seperated by space". b) When no match for the entered keyword is found, the JList display "No results found. Please try a more related keyword" So, I checked for those two scenarios and disabled the listener during their appearance in the JList. It works the very first time I start the JApplet. Thereafter, it just does'nt. You can execute the following code by itself and run it in a browser. Its simple and its working. Please find the bug.I am new to programming, so any new suggestions are more than welcome.
VIEWS ON THIS POST

37

Posted on:

Tuesday 23rd October 2012
View Replies!

JTree focuslistener problem

I have posted this topic once but I didnt receieve any reply. So I am posting it again . I want to add focuslistener to each tree node so that we focus gets lost from particular tree node I want to validate information associated with it. So I hope reply this time... Any alternative solution to this other than focuslistener...\t Thanx.. , hi, I have implemented using SelectionListener...
VIEWS ON THIS POST

44

Posted on:

Tuesday 23rd October 2012
View Replies!

jsplitpane resizing problem

hi, i have a jsplitpane that has a jscrollpane on the left on the right.The one on the left contans a jtree while the one on the right contains several jpanel(and different layout managers).The problem comes in the displayam of the split pane, its compressed and i have to manually resize it to see the components. i thot that on calling the frame's pack(), the frame is resized according to the components it contained but apparently this isn't the case.Further more, i displayed the components' sizes and they're all Dimension(0,0). Seems i forgot something , or should i expicitly set some minimum size to all jpanels .. am really not sure of what to do , so if anyone could give me an idea , i'd be super grateful.
VIEWS ON THIS POST

75

Posted on:

Tuesday 23rd October 2012
View Replies!

Jtable sorting; problem with getValueAt

Hi , I have implimeneted a sorting JTree (with a TableSorter). Problem is when the user clicks on the column, say length, the sorting is incorrect. (it sorts it as if it's a String; same goes to the sort by dueDate) I understand that the sorting is according to the object's type. the due date is a String in the example below but when converting to Date, the result is: Wed Aug 10 00:00:00 PDT 2005) (!) anyone knows how to correct this
VIEWS ON THIS POST

76

Posted on:

Tuesday 23rd October 2012
View Replies!

dialog modality problem

Hi , i am desperately trying to find a way to give the user the ability to do some actions on the main application while a dialog is open . typically , copy text from a JFace TextViewer into a find dialog . I am using JFace 3.1 / JDK 1.5 I have tried any combination of shell modes (primary , application , system , modeless ... ) nothing seems to work.
VIEWS ON THIS POST

39

Posted on:

Tuesday 23rd October 2012
View Replies!

JInternalFrame maximise problem

hi frenz ... my problem is I m making an application in which there are many JInternalFrames. I want to maximise or minimise them from Menu. code I m using is if(!(frame.isMaximizable())){ frame.getDesktopPane().getDesktopManager().minimizeFrame(frame); frame.setMaximizable(true); JInternalFrame[] frames=desktop.getFrames(); for(int i=0;i
VIEWS ON THIS POST

43

Posted on:

Tuesday 23rd October 2012
View Replies!

JAR - SWING - based problem

Hi , I would appreciate very much if you could give me some clue to solve the following problem I have. I have built a JAR file that simply opens the JFrame window when clicked the JAR file. So far everything is ok (JAR file get correctly opened) but I am wondering how it could be possible to prevent (block) a user from having one or several instances of one and the same JAR application This is now possible when user have clicked once my Jar app and having it opened, clicks another time the Jar app etc and finally there will be dozens of windows at one time. What could be the best and nicest way of resolving this problem p.s Hopefully you all have understood correctly my problem
VIEWS ON THIS POST

57

Posted on:

Tuesday 23rd October 2012
View Replies!

problem to listen key board event

I have to listen CTRL key event on panel... can any one send sample code......
VIEWS ON THIS POST

70

Posted on:

Tuesday 23rd October 2012
View Replies!

Swing - Listener with multiple sources problem

hey, i am designing a GUI for class timetables in my college and i have encountered the following problem: In the 'Master' frame i want the components at the top of the frame to change when the JRadioButtons do, i have four JRadioButtons in 2 ButtonGroups. they are -> o Class o Lecturer and -> o Add o Remove so different combinations of selected radio buttons will change what components appear above. Would i use an itemStateChanged listener or what would be the best way Could some1 please tell me a suggested solution because i have been stuck for sometime, or if you have had a similar problem yourself.
VIEWS ON THIS POST

36

Posted on:

Tuesday 23rd October 2012
View Replies!

setOpaque(false) problem..

I have a class that inherits from JComponent and it's opaqueness is set to false. As the result of this, the paintComponent method is no longer called. Everything works just fine when the opaqueness is set to true. Am I missing something obvious here setting opaqueness to false doesn't mean that the component be invisible now does it
VIEWS ON THIS POST

55

Posted on:

Tuesday 23rd October 2012
View Replies!

problem in JEditorPane.

Hi Friends, I have small problem with the JEditor Pane can some one help, the problem is that I want to view the HTML page from a specified offset with the editor pane. Thank you regards sham
VIEWS ON THIS POST

62

Posted on:

Tuesday 23rd October 2012
View Replies!

problem with JTextField

hi, pls someone how do u retrieve information from ur textfield once it has been entered by a user into the textfield and u do not want to use a button how do you go about writting an actionlistener for a JTextFiled thx in advance
VIEWS ON THIS POST

66

Posted on:

Tuesday 23rd October 2012
View Replies!

problem with focus listener

I registered focus lisener on JTextField. The listener getting called 2 times during 'TAB' out. Why does Focus Lost event gets called twice for all the JTextFields \t I want to do some valiadtion on 'TAB' out of JTextField Is there any alternative for this Please advise ..
VIEWS ON THIS POST

73

Posted on:

Tuesday 23rd October 2012
View Replies!