Swing/AWT/SWT :: Multiple Key Events?

Feb 5, 2014

Can you have multiple key events? by that I mean say you press the right arrow key, or a number on the numeric pad, then you press the letter c. does the second key event get fired? and i can catch both events?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: How To Cater For Multiple Special Events Of Life

Jan 15, 2014

My program has the following requirements.

Several kinds of celebration dates are displayed.

Say Marriage, a new baby is born and so on. Such special dates are not fixed to be once or twice.

Such that a person can have a marriage and a new born baby celebration or both. One of my thoughts was to used several (up to 3). JLabels and JDateChoosers, but it is quite limiting.

How should I design such a component so that it can accommodate several major events of life.

View Replies View Related

Open / Send Multiple Messages Over TCP And Close Connection On Events

Oct 7, 2014

I have a simple method in Java through which I send commands to a machine over TCP. The problem is:

Machine can't accept more than two connections in 20 seconds.

I need to send 15-20 commands to the machine in 3 minutes.

This is my current method which is not working as it should, 2 commands get transmited but third command hangs because of the machine.

void sendCommand(String command) throws IOException {
String ipaddress = "192.168.0.2";
Socket commandSocket = null;
BufferedWriter out = null;
BufferedReader in = null;
BufferedWriter outToDetailFile = null;

[Code] .....

Basically what i need is:

1st: I need to open the connection by calling method

public void openConnection(String ipaddress, String port){
//Code to start the connection
}

2nd: I need to be able to send commands to the connection I have already opened (i will send multiple messages in time period of 5-10 minutes):

public void sendCommand(String message){
}

3rd: Close that connection

public void closeConnection(){
}

View Replies View Related

Swing/AWT/SWT :: Paint Application - Mouse Events In Same Class

Apr 15, 2015

I have my paint application, i use the following mouse event to draw my shapes (mousePressed, mouseReleased, mouseDragged). Now after the user paint a circle for example, he must be able to drag the shape; to be able to do this. i think i must again implement the different mouse Events. I have done it and the drag is not working. How can i achieve this. can we implement multiple (mousePressed, mouseReleased, mouseDragged) in the same java class??

View Replies View Related

Swing/AWT/SWT :: How To Run Multiple Frames In BlueJ

May 27, 2014

I've been doing a course with a heavy focus on applets and AWT using BlueJ. I've branched out and learn to convert my applets to applications. I can successfully use frames to do similar things to applets (in BlueJ's applet viewer) but I can not seem to run more than application at a time (unlike applets where I could run several at the same time).

Below is a simple Hello World program I wrote. When I re-run main() it closes the original and starts again. (I'm aiming to explore the java.net.* libraries and for testing would like to use more than one frame at a time which can communicate to each over via sockets).

import java.awt.*;
import java.awt.event.*;
public class HelloWorld extends Frame implements WindowListener {
public static void main (String[] args) {
HelloWorld app = new HelloWorld();
app.setSize(500,500);

[code]....

View Replies View Related

Swing/AWT/SWT :: Multiple Values In Dialog Box

Feb 20, 2014

The below program ask the user to enter the value of x 1 , Y 1 and radius in separate boxes , What would look nice is if the user can Enter the Value X ,Y and radius in the same box.

import javax.swing.JOptionPane;
public class C3E29GeometryTwoCircles {
public static void main(String[] args) {
// Ask the user to enter the x1 coordinate.
String strNumber = JOptionPane.showInputDialog("Enter the value of x1 coordinate " );
double x1 = Double.parseDouble(strNumber);
strNumber = JOptionPane.showInputDialog("Enter the value of y1 coordinate " );
double y1 = Double.parseDouble(strNumber);

[code]...

View Replies View Related

Swing/AWT/SWT :: Multiple Action Listeners?

Oct 25, 2014

So im making a calculator just basic 4 function with a clear button. as i am working into this project i am running into an issue of assigning which click sets what. For instance i click the two button how do i tell it to assign it to firstNum, versus secondNum?

private class theHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
if(event.getSource()==one){
firstNum=1;
}
if(event.getSource()==two){
secondNum =2;
}
if(event.getSource()==three){
secondNum =3;
}

So this for instance allows me to set one to the firstNum and then add it to two or three but im not sure what to do next. I have in my mind i want to do something like make three listener classes, that operate in sequential order like you pick the first numbers, click an operation, and then select the second numbers then hit the operation(equal) button to display answer. Am i on the right track or what?

View Replies View Related

Swing/AWT/SWT :: Splitting GUI Into Multiple Classes?

Sep 12, 2014

I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.

Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?

View Replies View Related

Drawing Multiple Objects Swing

Jun 30, 2014

I have to do an assigment using Swing, where I have to make a Board(extends JPanel) and add multiple instances of moving elements to it, with following requirements:

By adding a new object to the Board, the others must not slow down. Also the user interface must not be blocked by the moving objects. So, the movement of the objects must be handled in a separate thread.

and

The application must support adding lots of objects, so it is not okay if every object has its own thread, as this would take too many resources. Design the application in such a way that it uses a constant number of threads, meaning that the number of threads does not grow when adding more objects.

The question is:

How to do this thing with constant number of threads?

View Replies View Related

Swing/AWT/SWT :: Using Multiple SwingWorker Threads

Aug 23, 2014

I have a Swing UI in which on click of Search button, I trigger the Search in 6 different modules in 6 Swing Worker threads. The results are returned by each Swing Worker class to the calling class.

I tried to use the below code to get the values returned from each thread. Now, I want to continue further only after all threads finish their execution. How to achieve this?

thread1.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (StateValue.DONE == thread1.getState()) {
try {

[Code] ....

I got several examples where the UI is updated direstly from multiple threads. I want the values to be returned to calling class because of below reasons:

1) When even one worker thread fails for some reason, I dont want to show the any result in the UI
2) Earlier, I was updating the UI in done() of every worker class. But, UI became inconsistent. E.g When one thread is in progress, other threads were completed and updating the UI which I dont want to do.

View Replies View Related

Swing/AWT/SWT :: Implementing Multiple Event Handlers

May 3, 2014

I'm having difficulty implementing keyboard and mouse event handlers at the same time for a program designed to notify the user when a key has been pressed or a mouse button clicked.

I can make and understand a program that does one or the other, but when I try to combine them, either the keyboard only or the mouse only works.

here is the code:

import java.awt.Color;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.event.MouseListener;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Display And Recolor Multiple Circles?

Feb 22, 2014

I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.

The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).

The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
public class FrameViewer {
public static void main(String[] args) {
JFrame frame = new JFrame();

[code]....

View Replies View Related

Swing/AWT/SWT :: Add DocumentListener To Validate Multiple JTextFields

Apr 22, 2013

Code given below does real time validation for 2 JTextFields. While entering some values to txt1 and txt2 enables the save button and removing values from txt2 or txt1 reset the save button to disable. I use Netbeans as IDE.What I want to do is, enable Save button after checking multiple JTextFields for validity. If any of the text fields is empty, btnSave must be disabled.This program gives expected result up to some extent. But there is little issue. After form appears for the first time, When I type something on Textfield1, Save button enables without checking Textfield2. This happens only at the first time.

public class NewJFrame extends javax.swing.JFrame {
private Boolean isValidFromTextField1 = true;
private Boolean isValidFromTextField2 = true;
public NewJFrame() {
initComponents();
btnSave.setEnabled(false);

[code]....

View Replies View Related

Swing/AWT/SWT :: Multiple JFrames - Thread And Progress Bar

Mar 29, 2014

I'm struggling with a small project. I have 2 jFrames. The first frame has a button that...

- Display's the second frame containing a progressbar
- Starts a heavy processing thread

I need to update the progressbar on the second jFrame, from a thread started on the first jFrame.

I have 2 problems:

- How do I update the progressbar?
- When the button is clicked, an empty second frame is displayed with no controls. The controls are only rendered/shown, after the large thread process is finished...

I've attached to this post a small screenshot, showing the main idea ...

Source code:

Button action on the first frame:

private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {
Progress progress = new Progress(); // The second frame
progress.setVisible(true);
clsProcess myProcess = new clsProcess(); // The thread process
myProcess.start();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Multiple Textfields Using FocusGained Event

Oct 11, 2014

I have a bunch of textboxes in a panel and I wanted to perform the same code when the user clicks into a textbox (select all the text in it). Right now I've started adding a focusgained listener to each textbox like this:

private void textField1FocusGained(java.awt.event.FocusEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
textField1.selectAll();
}
});
}

[Code]...

Is there a way I can have one focusgained listener that all the textfields can point to but have it pick the right textfield in the textFieldx.selectAll();?

View Replies View Related

Swing/AWT/SWT :: Setting Multiple Values To Textarea

Jun 18, 2014

I am making use of NetBeans IDE 8.0 to build a GUI. The idea is that I set multiple values received from textfields to textarea. This will enable me print the work. But ONLY ONE value from textfields is set(appear on textarea); the others do not appear at all. Below is example of what I mean:

String s = jTextField1.getText();
JTextArea1.setText(s);
String x =
jTextField2.getText();
JTextArea1.setText(x);

Only one is being set. The rest are not.

View Replies View Related

Events Associated With JMenuItems

Apr 24, 2015

So I am trying to finish this assignment I am not sure how to approach the last part of it. Basically, I need to give the drop down menu functions. For example if you press tennis it will give explanation about tennis lessons.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class JMenuFrame extends JFrame implements
ActionListener {
private JMenuBar mainBar = new JMenuBar();

[Code] ....

Attached image(s)

View Replies View Related

Swing/AWT/SWT :: JTable Using CTRL / Click For Multiple Row Selection

Jul 6, 2014

I know how to do single selection, but I would like to do multiple row selection only by using CTRL + click without the option of dragging the mouse to select rows. So the user would have to hit ctrl + click each time to highlight additional rows.

View Replies View Related

How To Use Events In Place Of For Loop

Jun 30, 2014

I have two questions:

1. I read somewhere that instead of looping through every player (below), you use could Events to do it for you:

for (Player player : this.getPlayers()) {
if (player.getLocation().getX() == 10) {
}
}

I'm not sure as to how to use Events in place of a for loop. I've been thinking on this for days, but I'm still stuck. Any example of using an Event instead of a for loop?

2. Is there any way to accept multiple connections on a server without using a while loop? Maybe use Events to handle the acceptance of connections?

View Replies View Related

Swing/AWT/SWT :: Listener Called Multiple Times On Single Click?

Jan 30, 2015

I have the following listener on a tableset of names:

ListSelectionListener singleListener=new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int row=e.getFirstIndex();
if (row==previousRow) {
row=-1;

[Code] .....

The println shows that getValueIsAdjusting is called 4 times when I click a single selection from the list. Is this normal behavior? If so how do I determine which call to really use. If not, where can I look to see why it is being called 4 times on a single click?

View Replies View Related

Testing Events Within Inner Class Using JUnit?

Apr 17, 2015

How do you test the events within an inner class using JUnit

// File: : events/SomePanel.java
// Purpose: Show use of named inner class listener.
 
import javax.swing.*;
import java.awt.event.*;
class SomePanel extends JPanel {
private JButton myGreetingButton = new JButton("Hello");
private JTextField myGreetingField = new JTextField(20);
 
[Code] .....

Code extract taken from: Java: Inner-class Listeners

Taking the above example, do I need to use myGreetingButton.doClick to trigger this event to test the respective variables/values being used ? Also the Actionlistener inner classes is private so doubt I can access this from JUnit Test class.

View Replies View Related

JavaFX 2.0 :: Gesture Events In JFXPanel

Jun 30, 2014

I'll try to catch gesture events (ZoomEvent, SwipeEvent, etc.) from fx controls (e.g., an ImageView) that are embedded in a JFXPanel. However, no gesture events are thrown for the embedded fx controls.

I've read How to integrate javaFX gesture management in a complex Swing application? and it seems that "there is no gesture recognition in a JFXPanel".
 
But I've also tried this code SwingHtmlDemo - Pastebin.com that embedds an fx WebEngine in a JFXPanel. In this example, I can Zoom and Swipe the google map displayed in the WebEngine.
 
My Questions are:
How does the gesture recognition in the WebEngine work?
Can I reuse the gesture recoginition of the WebEngine for other fx controls embedded in a JFXPanel?

View Replies View Related

I/O / Streams :: Continuously Reading Watch Events

Dec 6, 2014

I'm trying to synchronize two folders and their sub directories between a client and a server. I have a modified version of this class which I've posted below. In my Client class, I create a WatchDir object and call its processEvents() method in an infinite loop. The method returns a myTuple object (a struct containing the event type and a path object) if an event is registered and null if not.

The problem is that this only seems to work for the first event to happen in the directory (i.e. if I add a file to the watched folder, my WatchDir object.processEvents() returns one Tuple with an ENTRY_CREATE event and never returns another Tuple for other file additions/deletions/modifications that happen after). I'd like for processEvents to be continuously called (hence the infinite while) returning a Tuple each time some event occurs.

My modified WatchDir:

import static java.nio.file.StandardWatchEventKinds.*;
import static java.nio.file.LinkOption.*;
import java.nio.file.attribute.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;

[Code] ....

View Replies View Related

JSP :: Java Server Sent Events Not Working Correctly

Oct 10, 2014

Code structure :

Server : Java Servlet
Client : Simple JSP
Communication : Server Sent Events every 1 second
Here is the problem.

My code needed the server to send updates every one second to the client as stated above. Hence, I added a while loop with a sleep of 1000 milliseconds in the servlet code as shown below. The following strange behavior is observed:

- While the server is sending updates to the client, and the client window closes by mistake, the server does not stop sending updates It continues sending the data.
- When the client is re-opened, it sends data much faster (almost double). For example, the server sends 60 seconds worth of updates (60 updates) in just 25-30 seconds. The server sends faster updates not only for this round of updates, but also for any subsequent updates.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter writer = null;
try{

[Code]......

This server behavior is much unexpected. Am I writing the server side code wrong? I have looked around a lot and only found while loop method for modifying the server update interval. Is there any other method which I am missing?

View Replies View Related

JavaFX 2.0 :: Using Events For Additional Mouse Buttons

Mar 14, 2015

Is there a possibility to use events for additional mouse buttons, like the next or previous mouse buttons, in javafx? If I use the setOnMousePressed event on a node, it only throws an event for the "PRIMARY" "SECONDARY" and "MIDDLE" buttons.
 
node.setOnMousePressed(new EventHandler<MouseEvent>() {   
      @Override public void handle(MouseEvent mouseEvent) {
          System.err.println("mouse button: " + mouseEvent.getButton());
     }
});
 
If I use this java application [URL] .... it is also possible to throw events for the next or previous mouse buttons of the mouse. But not in my javafx application.

View Replies View Related

Capture OS Event And Reproduce Sequence Of Events

Feb 10, 2014

Need to develop a Java application to listen to all user events occurring in the (initially only Windows) operating system to record some kind of record and to reproduce the sequence of events below ...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved