How To Call Action Listener Automatically And Without Doing It Manually
May 16, 2014
I'm not a java developer, i'm a tester. I am currently testing a java swing application and to do that I have to automate how its used. IE I have to write code which will press buttons for me rather than depending on an end user to do this. I have managed to reverse engineer the entire application (hooray for me), however I am struggling to work out how to invoke methods that would typically be kicked off by a user pressing a button. how to I can call actionPerformed(ActionEvent ae) method which sits in the ATMMainPanel class?
I will be calling it from inside another method which is the equivalent of the main() method.
Java Code:
public class ATMMainPanel extends JPanel implements ActionListener {
[declarations here]
//here - User is pressing the Enter button after putting in pin.
public void actionPerformed(ActionEvent ae) {
[code performed when button is pressed]
} mh_sh_highlight_all('java');
I'm using Eclipse with the Window Builder Pro plugin to create a Java program. I noticed that when I had Eclipse create an action listener for a combobox in a Swing GUI it created an AWT listener.
Did I choose the wrong type of listener? I want my code to use the Swing components because I understand that they are more portable.
In my code 0,1,2 work fine an present my prompts an use my listener correctly but for some reason 3-6 is not an I don't know why? Here's my attached code.
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Guess extends JFrame
I have three JComboBoxes. When the user selects an entry in the first JComboBox the entries in the second are set. For this I use an Action extends AbstractAction which is bound to the first JComboBox.
I have also bound an Action to the second JComboBox.
Problem: this also fires when the entries on the second JCombox are added which leads to a Nullpointer.
I need a Listener which only reacts to user input, and does not react when the model of the JComboBox is changed.
I have buttons created on a frame and then I register the listener from a controller in a controller-view relationship.
When I click the button on the face, the action never executes for some reason. I thought maybe there was a problem registering the listener but I can call the buttons doclick() method and it executes as it should. Perhaps I'm overlooking something really obvious here but I can't see it.
again, when i click the button nothing happens. but if i add the following code
btnEight.doclick()
the actionPerformed invokes in theController as I intended.
You can see the entire project on GitHub so you can see the full context. The controller class contains the listener and the view class contains the buttons.
I am working on a 3D-Projekt, but that's not the point. I wanted to call a function to turn the camera and want, that the function ist called while the key is pressed. I tried following:
private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean pressed, float tpf) if (name.equals("Camera Left") && pressed) { setViewAngle(-1);
I think, I have to change the ActionListener "onAction", but I can't remember in which way. In the actual code the programm only once perform the action when the key is pressed.
I already tried :
while(pressed) {setViewAngle(-1)}
But that didn't work, but get the whole programm to halt.
I'm writing a program for exemplary reasons that is basically two text fields, one for a username, and one for a password. the way its written is asking testing for what is inputed into the text fields if its equal to a "valid" username and password. if it is, a variable representing that is set equal to 1. there is another if statement asking if the actionevent.getsource is equal to the name of the textfield. the issue I had was that when I ran the program, it seemed to only test for the first condition, so I got the same result from the program regardless of what I input into the text field.
The Code
Main class: import javax.swing.JFrame; public class Alpha { public static void main(String args[]){ log l = new log(); l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); l.setSize(360, 240); l.setVisible(true);
[Code] .....
The code originaly was written "eve.getSource() ==" but I changed that to see if it would resolve the issue with no avail. With it written this way, the program does nothing upon entering the text and pressing enter. Currently, there is nothing written to change the variable "val" to 1 to show that the username is valid. I did this because I can't figure out how I would go about doing this.
Need to write two files but getting an expected exception error.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Scanner; import java.io.FileWriter; public class TestingPanel extends JPanel
[Code] ....
TestingPanel.java:49: error: unreported exception IOException; must be caught or declared to be thrown FileWriter outputFileQuestions = new FileWriter("Test.txt"); ^ TestingPanel.java:50: error: unreported exception IOException; must be caught or declared to be thrown FileWriter outputFileAnswers = new FileWriter("Answers.txt");
I am getting the problem as If call the action class through the ajax, my property values not setting to the formbean class, How can I use the formbean to set the all my property values and getting in action class.
This is my first servlet program. I wanted to try a web application where "register" user module will be in servlet program.I can access my index.jsp but when I enter values and click submit.
I get "There is no Action mapped for namespace [/] and action name [RegisterUserServlet] associated with context path [/TrainingApplication]. - [unknown location]".
Here's my index.jsp file:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
I am new to programming in regards to I/O, channels, SSH, etc...
At the moment I am trying to transform the Shell.java program from the JCraft JSch examples; JSch - Java Secure Channel - Examples
The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.
I was thinking that maybe I have to use some other InputStream object at line 77 when setting the channels input stream instead of System.in, but I am not sure how to do this (but really I'm not sure if I'm even on the right tracks?). I believe all this confusion may be down to a misunderstanding with the general concepts involved with channels and I/O ...
For some reason, when I generate a Javadoc (using javadoc.exe of JDK 8), it displays Java-defined classes like java.lang.String and java.lang.Object by their full names rather than simply String or Object. Only the classes inside the packaged contents were represented by their simple names and linked to them (had visible coloured bolding). Was I supposed to manually include the Java API?
I am trying to transform the Shell.java program from the JCraft JSch examples : [URL] ....
The way in which I am trying to transform it is by instead of having the character input go into the channel automatically from the keyboard (refer to line 77 in Shell.java), I just want to pro-grammatically insert characters in to the channel at my discretion, so for example I have a string called unixCommand that I want to insert into the channel, and I don't want there to be any other way of inserting into the channel such as the standard input stream, so for example I'd have the statement <insert unixCommand to UNIX box at other side of channel> inserted somewhere after line 100 in Shell.java.
I was thinking that maybe I have to use some other InputStream object at line 77 when setting the channels input stream instead of System.in, but I am not sure how to do this (but really I'm not sure if I'm even on the right tracks?). I believe all this confusion may be down to a misunderstanding with the general concepts involved with channels and I/O.
My homework assignment is to create a program that reads two military times and then prints out the elapsed time. I've got all that down and ready to go but then the other part of this project is to have it loop until it is terminated manually. So at the end where it asks for a 'Y' or 'N' input answer is where I know i need to implement a do-while loop or switch statement, I'm not sure. how to make the application repeat until told to quit.
I have problem with manually (through my java code) selecting items in a JTree. I did Google the problem and found solutions here :
[URL]
This code worked for me only partially. Once I tried selecting deeper nested nodes, I ran into problems. Since my production code is very cluttered I built an example and reproduced my exact problem in it.
It streps through the tree by comparing user objects and finds the target node. Then it calls 'navigateToNode()' which uses the solution discussed in the links above.
This method behaves incosistently:
If you call it with an empty array it will correctly select the root node. The righthand pane shows the text of the selected node. = correct
If you call it with target node 1 it will correctly select node 1. The righthand pane shows the text of the selected node. = correct
If you call it with target node 1.1 it will select node 1.1 but for some reason it is not displayed as marked (no background). The righthand pane shows the text of the selected node. = only partly correct
If you call it with target node A it will run into an exception. Debugging reveals that the selection occurs correclty at first. You can also observe the righthand pane showing that 'A' was selected. But afterwards another TreeselectionEvent is occuring that has a NewLeadSelectionPath of null. I do not know where this second SelectionEvent is triggered from.
This code is run with Java 1.6.0_39 which is also what I will have to use in production.
If I get the bytecode with javap it seems to work:
Java Code:
Exception Table from to target type 26 30 40 any mh_sh_highlight_all('java');
But the problem is that I can't run the file anymore. Simply running it with the java command results in "java.lang.VerifyError: Expecting a stackmap frame at branch target 40". After some research this seems to be a problem with java 7 and a stricter verifier. I read several times that java -XX:-UseSplitVerifier should be used instead.
This really fixed the stackmap error, but then another error appeared: "java.lang.VerifyError: (class: AClass, method: signature: ()V) Inconsistent stack height 2 != 1". Are there any further steps required to insert a new exception in the exception table?
Additional info: Later I want to remove gotos (in this case the goto at line 27) and add a function call instead. When this function finishes it will throw a exception and propagate it back to the caller (which will be at line 27). Then the program should go on as if nothing happend, that is also the reason why the target of the exception is the same as the target of the goto (40)
I'm writing a JavaFX desktop app, and would like to make it automatically run after installation, but I'm not sure where to look to make this happen (or even if it's possible?). I have successfully created a .dmg installer using E(fx)clipse & Ant. Are there options I'm overlooking which I can use in the build.xml? or am I looking in the wrong place entirely?
The array size is fixed improve it to automatically increase the array size by creating a new larger array and copying the contents of the current array into it .I am using a course class and here is the code for the class
public class Course { private String courseName; private int numberOfStudents; private String[] students = new String[100]; public Course(String courseName)
[Code] ....
As you can see I have the array set to size 100, how do i make so it increments each time the user adds a student.
I am trying to get random shapes to generate automatically. I was able to get just three shapes to generate but nothing random. When I added the random code now only the frame shows up and no shapes. I also keep getting an error with frame.setVisible(true). It says identifier expected. Here is what I have so far:
Main program:
import javax.swing.*; import java.awt.*; import java.util.Random; public class ShapeGen { public static void main(String [] args) { //Create window and set title draw panel = new Draw();
[Code] ....
This is the draw program to generate random shapes:
import javax.swing.*; import java.awt.*; import java.util.Random; public class draw extends JPanel { public draw(Color backColor) { setBackground(backColor);
The program shall assign a new employee ID to the employee and display it on the screen.
The employee ID shall be generated by adding 1 to the largest employee ID already in the employee.txt data file.
You can see I've tried variations of identification++ but have not been successful. I've also tried to get the last or the highest identification in the arrayList but have not done that right.
public static void addEmployee() { String firstName = Validator.getString( sc, "Enter First Name: "); String lastName = Validator.getString( sc, "Enter Last Name: "); int identification = 0;
[Code] ....
I also can display all of the employees their identifications and their punches but I cannot narrow it down to searching one employee and displaying information for just the one.
-If the selected value is ‘I’, prompt the user to enter the employee’s ID number. -If ‘I’ is selected the display shall show the employee’s name and ID, list out each day worked in chronological order, the number of hours worked that day and a total number of hours worked in the two week period.
The report shall prompt the user to re-enter an employee ID of it does not exist in the employee file.
private static void displayReports() { System.out.println("Report"); Scanner sc = new Scanner(System.in); String action = " "; while (!action.equalsIgnoreCase("d"))
I'm working on an assignment that says the following.
" The array size is fixed in Listing 10.6. Improve it to automatically increase the array size by creating a new larger array and copying the contents of the current array to it.Implement the dropStudent method.Add a new method named clear() that removes all students from the course.
Write a test program that creates a course, adds three students, removes one, and displays the students in the course."
10.6 Listing
public class Course { private String courseName; private String[] students = new String[100]; private int numberOfStudents; } public Course(String courseName) { this.courseName= courseName;
[Code]...
My Test Code based off of book
public static void main(String[] args) { Course course1= new Course("Business"); course1.addStudent("Jay"); course1.addStudent("Silent Bob"); course1.addStudent("Dante"); course1.dropStudent("Jay");
[Code]....
My adjusted 10.6
public class Course { private String courseName; private String[] students = new String[100]; private int numberOfStudents; } public Course(String courseName) { this.courseName= courseName;
[Code]...
The problem I'm having is, for the first part of the question where I need to automatically increase the array size. I'm really not great at this stuff. I have tried breaking it down, but can't "get it", I guess.
I assume, it'd be a loop that checks to see if the student array is full and if so, do the increaseArray() part, by maybe multiplying the student array and then assigning it. I just don't know how to do it haha.
My *best* attempt at the loop so far has been
if (students == students.length){ int bigArray = 2*students.length; String increaseArray()= new String[students]; System.arraycopy(students, 0, increaseArray, 0, students.length); students= increaseArray;