Swing/AWT/SWT :: How Can Two Different Objects Receive Notification Of Same Event

Feb 23, 2015

The scenario:

* A pop-up menu generates an array of rectangle objects; each rectangle having random x.y coords and colour.
* The number of rectangles in the array is user selected from the popup list.
* The APopUp class has a 'getter' method that returns the array.
* The pop-up object is instantiated in an object of the AFrame class.
* The AFrame object needs to get the array each time the popup changes its state.

The problem:
.
* As I see it, the AFrame object needs to informed of the pop-up's state of change event or does the problem lie in how I have decided
which responsibilities each class is to have? I've tried to be as logical as possible during planning.

In the days of FORTRAN or BASIC we would hammer a solution through with brute force, but I would like to keep to Java's philosophy
of encapsulation and clean interfaces and that it seems to has generated a impasse of brain warping proportions.

import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class AFrame extends Frame implements ItemListener {

[code]....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Notification Window Minimized As The Messenger

Feb 17, 2014

I need that when my application is minimized notify you when something happens, like the messenger (MSN) remember? The window notifying a new message, the minimized window blink in orange, orange need not be ok? I do not even know where to start.

View Replies View Related

Swing/AWT/SWT :: Where Is Event Source Object

Feb 28, 2015

java.awt.Component is an abstract class, and it's direct Sub-classes are Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, Text Component

So, when I use addXListener(mylistenerclass m);//which is a method of Component class which object is holding the list of all listeners, for a particular Event Source?

I am under the assumption that - there is an Event Source Object(possibly static) for every Event Source type(mouse, keyboard etc) that holds a list of destinations(classes that implements their listener interface) - added to the the object via addXListener method. When an event happens(mouse click, drag etc) the Event Source Object creates an Event Object and send it to all the destinations. Is my assumption correct? I can't seem to find the location or declaration of Event Source Object and the list where it stores it's registered destinations.

View Replies View Related

Swing/AWT/SWT :: Event Driven Development

Feb 22, 2014

I think will be easy for me start with a GUI and then make things happens when the user clic on Buttons.Is there a good book about Event driven development on Java?

View Replies View Related

Swing/AWT/SWT :: Which Event Is Generated When Scrollbar Update

Jan 1, 2015

Which event is generated when a scrollbar is update?

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 :: Right Button Event Mouse In Jtable

Feb 18, 2014

I'm trying to can make right button event to show a popup of copy/paste in a jtable but I put these code and doesn't works:

public class UI implements ActionListener, DocumentListener, MouseListener{
private JFrame ventana;
private JTable table;
private JPanel panel;
private JScrollPane tableScrollPane;

[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 :: How To Pass On Object To Event Listener

Sep 22, 2014

I’m teaching myself Java. I am a fairly proficient programmer in other languages, but this is the first OO language I’m doing.I have a question that is a bit hard to summarize. Or it should be: how can I pass on an object (or variable) to an event listener?

I am writing an application in which you can play a Sudoku game. I have separated the “logic” or the “model”(the classes with Sudoku data structures and methods to manipulate them) from the presentation (the view and the controller).The main method starts off as follows:

SudokuModel model = new SudokuModel();
SudokuView viewController = new SudokuViewController(model);

The first line creates class for the logic and the second line creates the class for the view and the controller. Since the view and the controller need access to the business logic, the model is passed on to the ViewController class.The SudokuViewController class creates the user interface in Swing and it handles the user input. For the user input I have created a number of listeners, like this:

table.addKeyListener(this);

Now these listeners need access to the model since they update it. However, as far as I’m aware the only parameter passed on to an event listener is the event itself. So these event listeners do not have direct access to the model, even though it is passed on to the constructor of the class SudokuViewController.

To circumvent this, I made model2 an attribute (variable) of the class SudokuViewController. The constructor of the class sets this variable as follows:

model2 = model;

Now the event listeners have access to model2, which they can manipulate.This works. However, I think it is an ugly solution, introducing an additional object (model2). I’d like to pass on the object named model to the event listener, but this doesn’t seem to be possible.

View Replies View Related

Swing/AWT/SWT :: Event To Detect Jframe Change

Aug 13, 2014

I would like to detect when the user change de JFrame. I make:

public class UI implements ActionListener, ComponentListener, DocumentListener, MouseListener{

private JFrame ventana;
private JTable table;
private JPanel panel;
private JScrollPane tableScrollPane;

[Code] ....

I put componentResized but when I change JFrame I cant see the string that I put in the method.

View Replies View Related

Swing/AWT/SWT :: Table With JCheckBox - Fire Event On Click

Feb 10, 2015

I would like to get a checkbox within a table to fire an event when it's clicked rather. I gave tried putting in a TableModelListener but the the event only seems to trigger when I click on another column (as if the table is waiting to see if I will change my mind) before moving on.

I have also looked at the setValue of the TableModel itself.

Do I need to put an ActionListener on each checkbox or have I missed something ?

View Replies View Related

Swing/AWT/SWT :: How To Capture MouseClick Event From JTable Within A JScrollPane

Apr 15, 2009

I have a JTable that is within a JScrollPane. If I try to write add a MouseListener to the JTable it never fires. However, a mouse event does fire for the JScrollPane which it is added to. Is there a way to prevent the JScrollPane from capturing the event or passing it along to the JTable?

View Replies View Related

Show System Tray Or Desktop Notification From Web Application Based On Java

Nov 23, 2014

The explanation is a bit lengthy because I just tried to explain everything in one shot.

Link to the question

java - Show a System Tray notification or Desktop notification from the web application

View Replies View Related

Swing/AWT/SWT :: Disable Event While Performing Long Running Task

Apr 28, 2015

I have in my application a button that when it is pressed, runs a long running task (usually takes a couple of seconds....).

My problem is that while the task runs, I want to stop the button from receiving clicks. Unfortunately this is something I have not achieved.

I have tried creating a new thread and calling the long running method, and using the Display.geCurrent().asyncExec...

Examples of what I have tried so far:

myButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (myList.size() > 0) {
myButton.setEnabled(false);
myButton.setGrayed(true);

[Code] .....

In both cases, while the button is disabled and the cursor busy, if the user clicks the button, the long running method is ran several times - and this is what I want to avoid.

View Replies View Related

Swing/AWT/SWT :: JEditorPane Show Image When Event Click On Href

Mar 29, 2014

I want show one image when i click on one "href". I have write this code....

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

[Code] ......

View Replies View Related

Swing/AWT/SWT :: How To Show And Hide Panel In One JButton Click Event

Nov 23, 2014

In JButton's click event, I wanto to show a JPanel to print the message "Processing" on the screen. Before JButton's click logic end, hide the JPanel.

Actually, JPanel is not displayed. I do not know why.When msgPanel .setVisible(false); is commented out, JPanel is normally displayed .But do not know how to hide it when JButton's click logic is finished.

Here is the code.

 loadBtn.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
   JPanel msgPanel = new JPanel(rootFrame);
   // Show the message JPanel

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Program Doesn't Close Though WindowClosing Event Called

Mar 25, 2014

I use the right term, release resources because after clicking the close button, the DOS prompts becomes unresponsive. So I have to close the DOS prompt, then reopen it, then type in the path again for the Java folders. Can you check where did I go wrong with my code? Is my placement of the WindowListener and WindowAdapter incorrect? Please refer to my code below:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Proj6exe1 extends JFrame implements ActionListener
{
DataOutputStream dataLabas;
JTextField rainFallField;
JButton submit;
String strRainFall;
JPanel proj6Panel;

[code]...

I have other programs where the placement of the WindowListener and WindowAdapter are as exactly like this (within the class constructor block) where they close correctly and some that behave like this, that renders the DOS prompt unresponsive.

View Replies View Related

Swing - WindowStateChanged Event Updates Window Size After It Completes

Feb 12, 2014

I have a JFrame where some elements (one, for now) have to be centered manually on the contentPane when resizing the window or changing the window state. Resizing event (componentResized) works fine but the windowStateChanged event is causing problems because it doesn't seem to "update" the contentPane's new size properly - it keeps the previous value although the window's size is obviously changed. This can be seen by simply printing the result of getSize called on contentPane.

Centering is done by programmatically changing the constraint of the component (using putConstraint, SpringLayout). The issue is that getWidth used in that method returns "wrong" values which results in an uncentered component. Maybe another listener is needed here?

Additional info: Eclipse with WindowBuilder, Linux Mint 15, Java 1.7

I know about SSCCE guidelines but I cannot make this particular example both ready to compile and short.For unknown reasons, I am unable to post the code example. I keep getting this - "Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words."

addWindowStateListener(new WindowStateListener()
{
// no "@Override" was generated but it is the same with it
public void windowStateChanged(WindowEvent e)
{
System.out.println("EVENT: " + contentPane.getSize() + ", "
+ getExtendedState() + ", " + e.getOldState()); // amusingly, states are actually correct - interchanging between 0 (Frame.NORMAL) and 6 (Frame.MAXIMIZED_BOTH) when I maximize and "unmaximize"
tfArrayPanelCenter();

[code]....

View Replies View Related

Swing/AWT/SWT :: Can't Change Visibility Of Two JPanels When Calling Method From Button Event In Another Class

Dec 30, 2014

I have two classes involved in this portion. CheckIn_Search

(class #1) is my main UI and I am collecting search information from the user in a jPanel form. When they click "Search" it passes the search criteria to a method that contacts a web service and gets the results. These results are passed to coSearchResults

(class #2) that opens a jFrame and jTable (in modal format, over the main window created by CheckIn_Search.

The user selects a row in the table and that selection data is passed back to coSearchResults to populate a new jPanel form. When the data is passed from coSearchResults, I want to close its window, hide the first jPanel in CheckIn_Search and make the second jPanel visible. To accomplish this, I created a method in CheckIn_Search that simply hides/shows the panels (it will do more later).

I instantiate and call the method in CoSearchResults as part of the button click event. The problem is, it doesn't work. The panels are unaffected and there are no errors. I've put in break-points and it goes into the method.. Here is the coSearch_Results code.

Here is am retrieving the jtable row id and using the first value in the row to get the data from the table model as there is more data than what is displayed in the table. I'm sending that whole row of data to the method that changes visibility.

private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
// TODO add your handling code here:
int rowNum = jTable1.getSelectedRow();
String coNum = jTable1.getValueAt(rowNum,0).toString();
String[] text;

[code]....

View Replies View Related

Swing/AWT/SWT :: Window To Submit Data Freezing When Created Inside Mouse Clicked Event

Feb 18, 2014

I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form). I have almost figured out how to do this, except for one problem. By putting a variable inside my form window called "ready," and then in my main window running a loop that constantly checks if ready is true and doesn't proceed until its true, I can create the form window, modify the values in it (currently just one value called "difficulty" that's modified by a jSlider), and then when i click the "begin" button, ready is changed to true, the form window closes, and the main window can proceed. However, when I try to put the while loop checking the ready variable inside a mouseClicked method in the main window, the form window freezes when it opens, and you can't see any of its content or modify it in any way (you can't even close it).

Here is my code:

//form window class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class formWindow extends JFrame {
private JTextField instructions1;

[Code]...

View Replies View Related

Swing/AWT/SWT :: What Is Event-dispatching Thread For GUIs And Why Use It Over Main Thread

Sep 20, 2014

I'm currently learning about Swing but I can't get my head round this piece of the code. Here is a simplified gui (not interested in the gui part but the execution)

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
new SwingDemo();
}

I get the above, create a new instance of SwingDemo in the main thread which starts up the gui through the constructor. However, then the tutorial says that I should avoid doing the above but do this instead:

public class SwingDemo implements ActionListener {
SwingDemo(){
JFrame jfrm = new JFrame("Simple gui pro");
//rest of code
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { //why do this instead?
public void run(){
new SwingDemo();
}
});
}
}

Reading, it talks about an event-dispatching thread which has completely lost me... Why not just instantiate the object directly instead of creating another thread?

View Replies View Related

How To Receive SMS Using USB Dongle

Oct 21, 2013

Code to receive a SMS using an USB dongle? or else how to write a code? I searched in the internet but couldn't find it.

I'm using Netbeans IDE.

View Replies View Related

Swing/AWT/SWT :: Resize Objects From ArrayList

Jan 10, 2014

I have a problem with my program. My aim is to display in a JPanel, 2 rectangles from an arraylist, and resize them by clicking. I want to give the user the ability to change the height of the rectangles (independently) by moving the top and/or bottom edges. There is errors in my code but where ? Netbeans underlines 2 lines (in bold).

My code:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Path2D;

[Code]....

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 :: Iterating Through Objects To Draw On Panel?

Apr 23, 2014

I currently have the code set up to iterate through objects and keep track of them but how do I do the same and draw the objects on the panel window? I'm confused on what to do and how to start it.

Here's the code I have so far, the 'Car' which I want to draw extends to another class which extends to GameObject. I currently have a 'draw()' method under the 'Car' class but nothing in the 'draw()' method yet. From what I understand i'm suppose to have a 'draw()' method under 'GameObjects' class also?

public class MapView extends JPanel implements IObserver, ActionListener{
JPanel myPanel;
private Timer timer = new Timer(5, this);
int x = 0;
int moveX = 2;
public MapView(){
super.setBorder(BorderFactory.createTitledBorder("Map:"));

[code]....

Mostly I don't understand how to go through the iterator again to paint the objects. Wouldn't I need to put another iterator under 'paintComponent()' or can it be done under 'update()' ?

how to get some shapes from the GameObjects onto my panel.

View Replies View Related

Send / Receive Mass SMS And Update Database

Aug 4, 2014

I have just taken it upon myself to attempt to develop an application using java that will implement several features for my aircraft maintenance unit. I've taken a few courses in Java and I am a computer science major, so I wanted to use this as a way to improve my coding skills while also improving the effectiveness of my unit.

Anyway my application needs to have these key features:

1. Access a recall roster that is in Excel format and read the names/phone numbers of up to 200 members. The application also needs to be able to update this information and save it.

2. The application also needs to be able to initiate a recall to some or all of the members on the recall roster via text message.

3. The application needs to be able to receive messages back and display them under each name from the recall roster.

My current plan is to set up a GUI that expands JButtons in a scrollable window as members are read in from the excel document. Upon clicking any of the buttons the person will be contacted individually via a custom message that can be typed in via a popup window after clicking it. Alternatively you can check a box next to any persons button to add them to the list of people to be contacted and then click a button that says "Contact those checked" or something along those lines. Finally there will be a button that just says initiate total recall and it will contact everyone.

As for the interface I want each button to be highlighted red until a response has been received from the person associated with that button, which will then be recorded under their contact information.

I've attached an extremely rough picture...

View Replies View Related







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