Detecting event in swing
Hi
In my applet ,i have 2 buttons MyButton and MyButton2, but clicking on them is not giving me the result i want in my actionperformed method
public void actionPerformed(ActionEvent ae) {
try{
if(ae.getSource().equals(MyButton)){
objRequest.setEngine("Yahoo");
objRequest.setMessage(sField.getText().trim());
if(ae.getSource().equals(MyButton2)){
objRequest.setEngine("Excite");
objRequest.setMessage(sField.getText().trim());
can anyone tell me where i am going wrong?
thanks
achy
hi,
what should happen is that, depending on what button is pressed, the fields of the objRequest object that u see in the code should be changed. code is running fine except the ae.getsource.equals (MyButton/Mybutton2) is not working.
thanks
akhi
Similar Messages
-
PVC2300 - Alternative to Motion Detection Event / FTP Upload
Hi Cisco Community,
My apologies if I am not posting this in the correct section / allowed to post here.
I've got a PVC2300 mounted inside a pelco enclosure that is positioned 6 meters high. Sometimes the motion detection event doesn't work to well (this is due to the fact that its in an enclosure and pointed out towards the ocean at a beach location).
Also the motion detection event is pretty much useless at night without surrounding illumination.
In Australia we also have severe lack of broadband speed and also download allowance, therefore it is not practical to broadcast streaming video (we would get charged excessive fees for exceeding download quotas and only one person could view the camera at any one time).
I've written a custom windows service that reads the PVC2300's MJPEG stream over http at a specified interval and saves a single .JPG file in which the windows service uploads the .JPG file to a specified website. This means that you will always get an updated image from the camera every 5 minutes, rather than based on motion detection. It would have been nice if cisco / linksys implemented this within the camera's firmware (maybe in a future version?).
Anyway, communities share things with each other, so i've made the software freely available to anyone who wishes to use it. I would appreciate any feedback from Cisco / Linksys.
http://www.airbiscuit.com.au/pvc2300-service.html - PVC2300 Windows Service
http://www.airbiscuit.com.au/camera.aspx - The actual PVC2300 in operation
Regards,
David ZielinskiYou came to the right place and thats a very cool post IMO.
First, thanks for using Cisco Small Business products and you can look forward enhancements and options in our line, of course. I think I noticed your other post mentioning you are in Australia? We have a few really top BU folks (TMEs and Biz Dev) down under and they are very active in the BU solutions area for Small Business. Do you know Leah Davis and Dave Harper (they are Participants on this community as well)?
In any event, I think compressed streaming is a very valid design idea and we are actually looking at similar partners in the US experimenting with the same. In one Partners case he has a lightweight application (java) that runs on your mobile and allows all the mobile streams to come compressed from a server farm.
Typical use case is a Day Care where 15 parents want to watch the same camera, and the compression benefit becomes crucial in scale. But your case is a financial one (therefore good too) where you would have to pay for streaming video.
While we dont offer this today (the external managed service that is), I am sure you have played with the camera GUI and realize you can try some of the following to reduce bandwidth
1- lower quality of video (resolution, FPS, illuminate Audio, etc)
2- reduce motion detection size (seconds)
3- Purchase a local NSS2100 or NSS3x00 to store High Quality video on the LAN and only alert for motion via email (not realy friendly for remote monitoring I admit).
For sensitivity in an enclosure, have you played with Sensitivity settings thresholds in the Camera GUI under motion detection?
For night illumination without an external IR Illuminator, have you tried the 'night schedule', which activates (or deactivates) the IR Cut Filter?
For the periodic updates, I'll let Davin Oishi comment as he is about ready to announce the PVC300 and I know it offers a browser based periodic refresh and I am not sure how far he has extended that to an API for external access.....
Thanks for your post
Steve DiStefano
Systems Engineer in the US field channel
RTP, N.C. -
How to detect only single click and not double-click mouse events in Swing?
Hi,
In my application, I want to implement a functionality only for single click. But problem is on double click, first i can see a single click and then double click.
i.e e.getCount() return 1 and then 2 for double click. I want to avoid this situation.
Shouldn't it be just one event with a clickCount of 2? or any alternative solution?
Please let me know how can i stop this.
Thanks in advance..
Cheers
Somasekhar
Edited by: SomasekharPatil on Mar 13, 2009 3:36 PMMaybe something like the below example:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public class SingleClickOnly {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SingleClickOnly().createGUI();
public void createGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Only acts on a single click");
label.addMouseListener(createListener());
frame.add(label);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public MouseListener createListener() {
return new MouseAdapter() {
private int clickCount = 0;
private final Timer timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (clickCount == 1) {
System.out
.println("Executing action on click count 1 only");
timer.setRepeats(false);
@Override
public void mouseClicked(MouseEvent event) {
clickCount = event.getClickCount();
System.out.println("Clicked: " + clickCount);
if (clickCount == 1) {
if (timer.isRunning()) {
timer.stop();
timer.start();
}Piet -
Please add keyboard focus events to swing calculator. Its very argent.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
A frame with a calculator panel.
class CalculatorFrame1 extends JFrame
private static final long serialVersionUID=0;
public CalculatorFrame1()
setTitle("Calculator");
Container contentPane = getContentPane();
CalculatorPanel panel = new CalculatorPanel();
contentPane.add(panel);
pack();
setVisible(true);
public static void main(String[] args)
CalculatorFrame1 frame = new CalculatorFrame1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.show();
A panel with calculator buttons and a result display.
class CalculatorPanel extends JPanel implements KeyListener
private static final long serialVersionUID=0;
private JTextField display;
private JPanel panel;
private double result;
private String lastCommand;
private boolean start;
public CalculatorPanel()
setLayout(new BorderLayout());
result = 0;
lastCommand = "=";
start = true;
// add the display
display = new JTextField("");
// display.addKeyListener(this);
// display.addKeyListener(this);
add(display, BorderLayout.NORTH);
display.setFocusable(true);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
// add the buttons in a 4 x 4 grid
panel = new JPanel();
panel.setLayout(new GridLayout(5, 4));
addButton("7", insert);
addButton("8", insert);
addButton("9", insert);
addButton("/", command);
addButton("4", insert);
addButton("5", insert);
addButton("6", insert);
addButton("*", command);
addButton("1", insert);
addButton("2", insert);
addButton("3", insert);
addButton("-", command);
addButton("0", insert);
addButton(".", insert);
addButton("=", command);
addButton("+", command);
addButton("Clear", command);
add(panel, BorderLayout.CENTER);
//this.addKeyListener(this);
Adds a button to the center panel.
@param label the button label
@param listener the button listener
private void addButton(String label, ActionListener listener)
JButton button = new JButton(label);
button.addActionListener(listener);
panel.add(button);
This action inserts the button action string to the
end of the display text.
private class InsertAction implements ActionListener
public void actionPerformed(ActionEvent event)
String input = event.getActionCommand();
if (start)
display.setText("");
start = false;
display.setText(display.getText() + input);
This action executes the command that the button
action string denotes.
private class CommandAction implements ActionListener
public void actionPerformed(ActionEvent evt)
String command = evt.getActionCommand();
// System.out.println("The value clear"+command);
if (command.equals("Clear"))
display.setText("");
start = false;
else
if (start)
if (command.equals("-"))
display.setText(command);
start = false;
else
lastCommand = command;
else
calculate(Double.parseDouble(display.getText()));
lastCommand = command;
start = true;
Carries out the pending calculation.
@param x the value to be accumulated with the prior result.
public void calculate(double x)
if (lastCommand.equals("+")) result += x;
else if (lastCommand.equals("-")) result -= x;
else if (lastCommand.equals("*")) result *= x;
else if (lastCommand.equals("/")) result /= x;
else if (lastCommand.equals("=")) result = x;
display.setText("" + result);
public void keyTyped(KeyEvent e) {
//You should only rely on the key char if the event
//is a key typed event.
int id = e.getID();
String keyString="";
System.out.println("The value KeyEvent.KEY_TYPED"+KeyEvent.KEY_TYPED);
if (id == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
//System.out.println("The value c"+c);
if(c=='*' || c=='/' || c=='-'||c=='+' || c=='=')
start = true;
else
start = false;
keyString = display.getText()+ c ;
System.out.println("The value keyString"+keyString);
else {
calculate(Double.parseDouble(display.getText()));
start = true;
display.setText(keyString);
public void keyPressed(KeyEvent e) {
//You should only rely on the key char if the event
//is a key typed event.
String keyString;
int id = e.getID();
if (id == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
keyString = "key character = '" + c + "'";
} else {
int keyCode = e.getKeyCode();
keyString = "key code = " + keyCode
+ " ("
+ KeyEvent.getKeyText(keyCode)
+ ")";
display.setText("keyPressed:::"+keyString);**/
public void keyReleased(KeyEvent e) {
//You should only rely on the key char if the event
//is a key typed event.
String keyString;
int id = e.getID();
if (id == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
keyString = "key character = '" + c + "'";
} else {
int keyCode = e.getKeyCode();
keyString = "key code = " + keyCode
+ " ("
+ KeyEvent.getKeyText(keyCode)
+ ")";
display.setText("keyReleased:::"+keyString);**/
}Please state why the question is urgent?
You where given a suggestion 7 minutes after you posted the question, yet it has been over 2 hours and you have not yet responded indicating whether the suggest helped or not.
So I gues its really not the urgent after all and therefore I will ignore the question.
By the way, learn how to use the "Code Formatting Tags" when you post code, so the code you post is actually readable. -
Listen for an events for Swing objects in a separate class?
Hi all, sorry if this is in the wrong section of the forum but since this is a problem I am having with a Swing based project I thought i'd come here for help. Essentially i have nested panels in separate classes for the sake of clarity and to follow the ideas of OO based development. I have JPanels that have buttons and other components that will trigger events. I wish for these events to effect other panels, in the Hierachy of my program:
MainFrame(MainPanel(LeftPanel, RightPanel, CanvasPanel))
Sorry I couldnt indent to show the hierarchy. Here LeftPanel, RightPanel and CanvasPanel are objects that are created in the MainPanel. For example i want an event to trigger a method in another class e.g. LeftPanel has a button that will call a method in CanvasPanel. I have tried creating an EventListner in the MainPanel that would determine the source and then send off a method to the relevant class, but the only listeners that respond are the ones relevant to the components of class. Can I have events that will be listened to over the complete scope of the program? or is there another way to have a component that can call a method in the class that as an object, it has been created in.
Just as an example LeftPanel has a component to select the paint tool (its a simple drawing program) that will change a color attribute in the CanvasPanel object. Of course I realize i could have one massive Class with everything declared in it, but I'd rather learn if it is possible to do it this way!
Thanks in advance for any help you can offer
Lawrence
Edited by: insertjokehere on Apr 15, 2008 12:24 PMThanks for the response, ive added ActionListneres in the class where the component is, and in an external class. The Listeners work inside the class, but not in the external class
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public class LeftPanel extends JPanel implements ActionListener {
/* Constructing JButtons, null until usage of the constructor */
JButton pencilBut;
JButton eraserBut;
JButton textBut;
JButton copyBut;
JButton ssincBut;
JButton ssdecBut;
ActionListener a = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.print("\nNot supported yet.");
/* The Top Panel contains the title of program */
public LeftPanel(Dimension d){
/* Sets up the layout for the Panel */
BoxLayout blo = new BoxLayout(this,BoxLayout.Y_AXIS);
this.setLayout(blo);
/* Sets Up the Appearance of the Panel */
this.setMinimumSize(d);
this.setBackground(Color.RED);
this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
/* Pencil Tool */
pencilBut = new JButton("Pencil");
pencilBut.setAlignmentX(Component.CENTER_ALIGNMENT);
pencilBut.setActionCommand("pencil");
pencilBut.addActionListener(a);
this.add(pencilBut);
/* Eraser Tool */
eraserBut = new JButton("Eraser");
eraserBut.setAlignmentX(Component.CENTER_ALIGNMENT);
eraserBut.addActionListener(a);
this.add(eraserBut);
/* Text Tool */
textBut = new JButton("Text");
textBut.setAlignmentX(Component.CENTER_ALIGNMENT);
textBut.addActionListener(a);
this.add(textBut);
/* Copy Previous Page */
copyBut = new JButton("Copy Page");
copyBut.setAlignmentX(Component.CENTER_ALIGNMENT);
copyBut.addActionListener(a);
this.add(copyBut);
/* Stroke Size Increase */
ssincBut = new JButton("Inc");
ssincBut.setAlignmentX(Component.CENTER_ALIGNMENT);
ssincBut.addActionListener(a);
this.add(ssincBut);
/* Stroke Size Decrease */
ssdecBut = new JButton("Dec");
ssdecBut.setAlignmentX(Component.CENTER_ALIGNMENT);
ssdecBut.addActionListener(a);
this.add(ssdecBut);
System.out.print("\nLeftPanel Completed");
public void actionPerformed(ActionEvent e) {
System.out.print("\nAction Performed");
}But this is not picked up in my external class here
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public class MainPanel extends JPanel implements ActionListener {
/* Creates a new the main JPanel that is used in the FlipBookFrame to contain all of the elements */
public MainPanel(){
/* TopPanel constraints*/
tpcs.gridx = 1;
tpcs.gridy = 0;
tpcs.gridwidth = 1;
tpcs.gridheight = 1;
tpcs.fill = GridBagConstraints.BOTH;
tpcs.weightx = 0.0;
tpcs.weighty = 1.0;
/* LeftPanel Constraints*/
lpcs.gridx = 0;
lpcs.gridy = 0;
lpcs.gridwidth = 1;
lpcs.gridheight = 3;
lpcs.fill = GridBagConstraints.BOTH;
lpcs.weightx = 1.0;
lpcs.weighty = 1.0;
/* CentrePanel Constraints*/
cpcs.gridx = 1;
cpcs.gridy = 1;
cpcs.gridwidth = 1;
cpcs.gridheight = 1;
cpcs.fill = GridBagConstraints.NONE;
cpcs.weightx = 0.0;
cpcs.weighty = 0.0;
/* RightPanel Constraints*/
rpcs.gridx = 2;
rpcs.gridy = 0;
rpcs.gridwidth = 1;
rpcs.gridheight = 3;
rpcs.fill = GridBagConstraints.BOTH;
rpcs.weightx = 1.0;
rpcs.weighty = 1.0;
/* BottomPanel Constraints*/
bpcs.gridx = 1;
bpcs.gridy = 2;
bpcs.gridwidth = 1;
bpcs.gridheight = 1;
bpcs.fill = GridBagConstraints.BOTH;
bpcs.weightx = 0.0;
bpcs.weighty = 1.0;
this.setLayout(gblo); //Sets the Layout of the panel to a GridBagLayout
this.add(tp, tpcs); //Adds the TopPanel to the MainPanel using the TopPanel layout
this.add(lp, lpcs); //Adds the LeftPanel to the MainPanel using the LeftPanel layout
this.add(cp, cpcs); //Adds the CanvasPanel to the MainPanel using the CanvasPanel layout
this.add(rp, rpcs); //Adds the RightPanel to the MainPanel using the RightPanel layout
this.add(bp, bpcs); //Adds the BottomPanel to the MainPanel using the BottomPanel layout
gblo.layoutContainer(this); //Lays Out the Container
public PanelSizes getPanelSizes(){
return ps;
public void actionPerformed(ActionEvent e) {
System.out.print("\nExternal Class finds event!");
/*String command = e.getActionCommand();
if (command.equals("pencil")){
System.out.print("\nYESSSSSSSSSSSSSSSSSSSSS!");
/* Create of objects using the PanelSizes funtions for defining the */
PanelSizes ps = new PanelSizes(); //Creates a new PanelSizes object for sizing the panel
CanvasPanel cp = new CanvasPanel(ps.getCentrePanelDimension()); //Creates a new Canvas Panel
TopPanel tp = new TopPanel(ps.getHorizontalPanelDimension()); //Creates the TopPanel
BottomPanel bp = new BottomPanel(ps.getHorizontalPanelDimension()); //Creates the BottomPanel
LeftPanel lp = new LeftPanel(ps.getVerticalPanelDimension()); //Creates the LeftPanel
RightPanel rp = new RightPanel(ps.getVerticalPanelDimension()); //Creates the RightPanel
/* I have chosen to create individual constraints for each panel to allow for adding of all
components a the end of the constructor. This will use slightly more memory but gives clarity
in the code */
GridBagConstraints cpcs = new GridBagConstraints();
GridBagConstraints tpcs = new GridBagConstraints();
GridBagConstraints bpcs = new GridBagConstraints();
GridBagConstraints lpcs = new GridBagConstraints();
GridBagConstraints rpcs = new GridBagConstraints();
GridBagLayout gblo = new GridBagLayout();
}Any help will be greatly appreciated :-) -
I am working on a C# NIDAQmx application for a hardware configuration that uses a PCIe-6321 to interface with downstream hardware. There is a DI signal from a manual switch on the downstream hardware that I must monitor for the start/stop signal for my application's data acquisition operations.
I was having inconsistent results using the ConfigureChangeDetection NIDAQmx functionality. So I used the ReadDigChan_ChangeDetection sample and using Debug.WriteLine statements have verified that when the switch on the hardware is toggled, multiple ChangeDetected events are thrown before the signal settles into the actual High or Low state.
Since I am not a hardware guru, I consulted another engineer, and was told that this is common with switches, and the signal and/or change detection needs to be "debounced".
Can this be done purely through additional configuration of the NIDAQmx DI task? I saw properties for digital filtering, but don't understand their use. I looked at the ReadDigChan_ChangeDetection_DigFilter sample, but it seems to imply that some other DI needs to be connected on the card to be used as the filter, which I don't have. Only one DI is coming from the downstream hardware.
Any help and/or advice will be greatly appreciated.I believe I have found the solution. By searching the forums I came across a couple of posts that pointed to this article
http://digital.ni.com/public.nsf/allkb/220083B08217CFD686257131007E5D2C?OpenDocument
So i started playing with the corresponding properties in the C# task, and it looks like I may have to only set the following properties:
myTask.DIChannels[0].DigitalFilterEnable = true;
myTask.DIChannels[0].DigitalFilterMinimumPulseWidth = 10.240000e-6;
According to error messages, the DigitalFilterMinimumPulseWidth for the PCIe-6321 can only be set to specific values.
Using this in the ReadDidChan_ChangeDetection_Events sample appears to be successfully debouncing the ChangeDetection events to only 1 per physical switch toggle.
If this is not the approach I should be using, please advise otherwise. -
Event Handling - Swing Window to Console Switch
I have a serious problem with an app I am writing - I have a swing 'main menu' system built around a standard JFrame which calls a new instance of another class. This other class takes input from the keyboard and is displayed in the standard console window; i.e Using the standard System.out.print() syntax.
My problem is the Swing window will not release the input stream to allow the conole to take input from the keyboard. I have implemented inner-classes within the 'main menu's' class for event handling purposes; in this case the mouse-clicks of the menu's JButton components. The problem only manifests itself when the inner-class' event handling code is called - I wrote some test methods to call the console classes code without using the inner-class' and the console works perfectly. It is my conclusion, therefore, that the calling of the console-based method from within the inner-class of the Swing super-class reserves the input for the Swing components, failing to reactivate the console. I have tried creating new InputStream objects but to no avail.
Does anyone know how to release or terminate the methods within the inner-classes (they are all void / no return type as they implement the ActionListener abstract class)? This, I hope, will return the focus to the console.
Any advice would be most greatfully received.
LEC.If you were to have your connection object declared so that it could be referenced from anywhere in your class then you could use it in you actionPerformed method. For example:
public class Test extends JFrame
   private Connection con = null;
   public void actionPerformed(ActionEvent e)
   {
      MyDetails appmydet = new MyDetails(con, id); //connection, userID
      appmydet.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
   }
   public void setConnection(Connection theCon)
   {
      con = theCon;
   } -
Please help me in KeyTyped Event in Swing
hi,
goodmorning
In my project I have a Frame.on that Frame I put a JDesktopPane which contains one JInternalFrame.I wrote coding in KeyTyped event and mouse clicked event of all i,e in my JFrame,JDeskotpPane and JInternalFrame.
No problem in all my mouse clicked events.When I click the mouse in my objects the corresponding actions done.
But when I typed keys in my JFrame only works well.When I type keys in my jDesktopPane or JinternalFrames nothing happen.will you please explain me what is the reason and the solution.Well, I am not a swing guru, so my answer may not be correct. My assumption is that you have to add the KeyListener not just for your Frame but for all the components inside the Frame.
For that you have to add a container listener so that when you add new components to your Frame, you might as well add the KeyListener for that. I will give you a link, so that it may explain you better than what I did, because I am a newbie too... :)
Here's the link: http://java.sun.com/docs/books/tutorial/uiswing/events/containerlistener.html
When a new component is added, add the key listener for that component, and check whether the newly added component is a container, if it is a container, then add the container listener to that component... All these things must be done in the componentAdded(ContainerEvent e) method.
In my project I have a Frame.on that Frame I put a
JDesktopPane which contains one JInternalFrame.I
wrote coding in KeyTyped event and mouse clicked
event of all i,e in my JFrame,JDeskotpPane and
JInternalFrame.
No problem in all my mouse clicked events.When I
click the mouse in my objects the corresponding
actions done.
But when I typed keys in my JFrame only works
well.When I type keys in my jDesktopPane or
JinternalFrames nothing happen.will you please
explain me what is the reason and the solution. -
Hello all
I have created a Frame, a menu bar, a panel which contains a split pane. In the first place, I would like to create a button in my leftsplitpane and that should happen when I click one of my menuitems. I hope I am clear. I have called the action listener for that. To make it simple, lemme show u a small part of my code.
private void ActionPerformed1(java.awt.event.ActionEvent evt)
javax.swing.JButton button1;
button1 = new javax.swing.JButton("Hit Me");
scrollPane1.add(button1);
mainPanel.revalidate();
The problem is that it is not showing any errors and it is neither displaying the button.
I would appreciate your help.
Thank youHere's a simple case of what I think you want.import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
Container content = getContentPane();
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content.setLayout(new FlowLayout());
JMenuBar jmb = new JMenuBar();
setJMenuBar(jmb);
JMenu jm = new JMenu("Menu");
jmb.add(jm);
JMenuItem jmi = new JMenuItem("Item");
jm.add(jmi);
jmi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
content.add(new JButton("Button"));
content.validate();
setSize(300, 300);
setVisible(true);
public static void main(String args[]) { new Test(); }
} -
Hi,
I'm trying to detect when a user double clicks on a selection screen, how to detect that this has been done and call some code.
I have the code for radio button etc.. which you set using the PF-status screen, but how do I detect when a user double click a line, and details for that line?
AT SELECTION-SCREEN.
PERFORM check_fields.
AT USER-COMMAND.
IF sy-lsind = 1.
CLEAR w_list_screen.
ENDIF.
CASE sy-ucomm.
*--- list spool screen
WHEN 'UPDA'.
PERFORM refresh_spool_list.
WHEN 'DPRI'.
PERFORM print_spool.
WHEN 'DELE'.
thanksHi Sims,
I understood that you want to raise an event when the user double click on a particular line in the report output. For this,
If you are using standard PF status (ie. you have not specified a PF status) then use the event AT LINE SELECTION. For getting the field you have double clicked use the command HIDE. Please have a look at the help of these two.
If you are using your own PF status, then give a status code for 'F2' and write the code in the AT USER COMMAND event as you did for others.
Hope this will help you.
Thanks
Vinod -
I've only spent 30 days with AppleScript, so I'm still asking questions like "Can AppleScript get messages or does it only send them?"
Here's what I'm getting at. Is there a way for an AppleScript to detect when iTunes changes tracks, when it reaches the end of a playlist, or if the user changes iTune's playing state?
Similarly, can a script detect when the user opens a new movie in QuickTime (or selects a new movie).
I'm imagining in pseudo code:
on iTunesEvent theEvent
-- script here
end iTunesTimeEvent
on QuickTimeEvent theEvent
-- script here
end QuickTimeEvent
Anything like that?
In other words, does iTunes send a message when such event occurs. If not, then my script must regularly get the state of those properties from iTunes and determine if they've changed, correct?
I've received VERY helpful advice and insights on these forums! Many thanks to all! Through your help I've got a powerful tool I'll use almost every day in my work.
JohnWhat you're asking for is a feature known as attachability - the abilty to attach a script to an application.
It is possible to do in AppleScript, but the catch is that the application developer has to specifically support it in his app. Like the vast majority of applications iTunes doesn't do this.
The only way you can do what you describe is to periodically poll the app to find out what it's doing. iTunes supports a 'player state' property that tells you what it's doing, plus a 'current track' property that identifies the current track being played (if any).
Something like this should work (untested):
<pre class=command>global lastTrack
on run
-- initialize a variable to store the current track
set lastTrack to missing value
end run
on idle
tell application "iTunes"
if (get player state) = playing then
set curTrack to (get current track)
if curTrack ≠ lastTrack then
-- we're not playing what we were playing last time we checked, so:
display dialog "Now playing " & name of curTrack giving up after 5
-- record the current track for prosperity
set lastTrack to curTrack
end if
end if
return 10 -- check again in 10 seconds
end idle</pre> -
How can I handle touch screen events with Swing?
Hi,
I was wondering how i can handle touch screen events. Are there APIs for that or is it just a mouse event?
Thank you in advance.
TimI have recently created an application that ran on a touch screen system. I used the normal mouse events attached to the swing components (onClick) and these were translated by the touch screen. Typically I created a calculator type keypad, touched the screen on the text box where I wanted the data to appear and then pressed the keypad buttons to populate the field. No special drivers, just using swing components
Hope that helps
yeah, this is really useful info.. me too trying to build an application for the touch screen... just wondering how other events like focus gained, tree selection events are recognized by touch screen? can we have focus and tree, table selection events etc, as it is in the touch screen as well?? or everything is just mouse event only?? -
How to assign the enter pressing to the button click event of swing button?
Hello to all you pro's,
I can't find how to make my button a default button so it will respond to an enter press.
any help will be most appreciated.
thanks in advanced.get the RootPane and call setDefaultButton on it. Something like so:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class SwingFu2 extends JPanel
private JButton buttonOK = new JButton("OK");
private JButton buttonCancel = new JButton("Cancel");
private JTextField textfield = new JTextField(12);
private JFrame frame;
SwingFu2(JFrame frame)
this.frame = frame;
ActionListener buttonActionListener = new ButtonActionListener();
buttonOK.addActionListener(buttonActionListener);
buttonCancel.addActionListener(buttonActionListener);
add(textfield);
add(buttonOK);
add(buttonCancel);
frame.getRootPane().setDefaultButton(buttonOK);
private class ButtonActionListener implements ActionListener
@Override
public void actionPerformed(ActionEvent e)
String command = e.getActionCommand();
if (command.equalsIgnoreCase("OK"))
System.out.println("OK pressed");
System.out.print("Text in textfield: ");
System.out.println(textfield.getText());
else if (command.equalsIgnoreCase("Cancel"))
frame.dispose();
private static void createAndShowUI()
JFrame frame = new JFrame("SwingFu1");
frame.getContentPane().add(new SwingFu2(frame));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args)
java.awt.EventQueue.invokeLater(new Runnable()
public void run()
createAndShowUI();
} -
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class s implements ActionListener
static int x;
public void actionPerformed(ActionEvent e)
System.out.println("performed action");
public Component createcomponent()
JButton but1 = new JButton("button1");
but1.addActionListener(this);
JPanel pane = new JPanel();
pane.add(but1);
return pane;
public void create_frame()
JFrame frame =new JFrame();
s s1 =new s();
Component pane1=s.createcomponent();
frame.setContentPane(pane1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
public static void main(String args[])
create_frame();
the above code dosent work it is showing errors like non static method cannot be referenced from static contex.
since iam new to java i cant figure out the why it is so, can somebody plz explain this.static variable/methods are at class level, meaning you can access them if you can access the class.
instance variable/methods are at instance level. Until you have an instance, you cannot call the methods.
In your example create_frame cannot be called because you don't have an instance. -
Order of focusLost and actionPerformed events in Swing on Red Hat
Hi!
I have quite complicated bug, which must be fixed as soon as possible. Currently I am drinking my fifth coffee and I cannot find anything about this bug on the net.
The bug looks like that:
I have pane with several JTextField on it and a Save Button.
Each JTextField has FocusListener with focusLost method. On focusLost event the entered text is validated and moved to the model object.
After pressing the Save Button model object is saved to DB. This work perfect on Windows but not on Red Hat ( I have not yet check on Solaris).
I enter the text in text field and press the save button with mouse. Then I receive information that the actionPerformed is called and save model object without entered text. After saving the focusLost is invoked and move the entered text to the previous saved object.
I have look into several books but I haven't find any information about order of events. Maybe if I took some more time, but project dead line is soon.
This is not my application, I only maintain it. I cannot read the JTextField on actionPerformed due to validation of data.
Have someone any experience with such problem?
I will be very appreciated for any help.I haven't receive any reply yet, but maybe my workaround will help someone else.
I have figured out, that if I implement actionPerformed as InvokeLater it will cause proper order of focusLost and actionPerformed.
So it looks like:
actionPerformed() {
SwingInvoke.invokeLater(new Runnable() {
createSaveThread()
startSaveTread()
}Have a nice day :)
Maybe you are looking for
-
Not allow to change payment terms
When creating a sales order, not allow to change the payment terms. can I block it? Thanks!
-
Bluetooth and keyboard system preferences not working
Hi all, When I try to change the keyboard system preferences or the bluetooth system preferences, the 'application' locks up (Doesn't bring up any details, force quit gets out of it). I've tried leaving it for ages to see if it eventually opens but i
-
To keep things tidy after finishing a project, I want to store everything related to the project in one folder and leave that folder on a big ext HD. To facilitate that, how about if I put the .fcp file in the Final Cut Documents folder while the pro
-
Problem with 8.1.6 after migrating to Tru64 5.1A
We just migrate our OS from Tru64 4.0G to Tru64 5.1A. Our database are 8.1.6.3.1. After migration the OS we had problem (ORA-07445) with some of our database. It seems that the problem is related to direct IO and a workaround is to set the DISK_ASYNC
-
Want to stream audio of church services...use iChat?
Hi all, I have a friend who is very ill and cannot be in our weekly services. She is able to use a computer with her eyes (blinking). We would like to purchase a MacBook to broadcast this service live. We don't need video, just audio. Would iChat be