Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

synchronized frames 1

Status
Not open for further replies.

chessbot

Programmer
Mar 14, 2004
1,524
US
I have a JFrame which gathers information from the user. In this frame, after it has been constructed, I call a synchronized method that wait()s until the user presses a button. After the button is pressed, the value is returned and the window closes.

Under most circumstances, this works fine. However, when accessed from another frame through an event, the paint() function of the inputting frame is never called. Any hints or suggestions of other ways to make my own user prompt?

I can post the code if necessary.
 
I'm no Swing expert, but you are probably screwing the event queue via your synch'd method.

Remove the "synchronized" from the method, recompile & retry - if you experience the same problem, then this is not the cause, otherwise it is ...

--------------------------------------------------
Free Database Connection Pooling Software
 
im not explaining it well. here is some code i made to test.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AnotherFrameClass extends JFrame
{
	public AnotherFrameClass()
	{
		setTitle("I've been framed!");
		setBounds(267,200,267,200);
		JButton test=new JButton("Test");
		getContentPane().add(test);
		test.addActionListener(new ButtonH());
	}
	public AnotherFrameClass(String title)
	{
		setTitle(title);
		setBounds(0,0,300,300);
	}
	class ButtonH implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			test();
		}
	}
	public void test()
	{
		System.out.println(MyVeryFirstFrame.test());
	}
	public static void main(String args[])
	{
		JFrame afc=new AnotherFrameClass();
		afc.show();
	}
}
and MyVeryFirstFrame (no reason for the name) is
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyVeryFirstFrame extends JFrame
{
	ImageArray ia;
	public int x=333;
	public MyVeryFirstFrame()
	{
		super("...");
		setBounds(200,200,128,74);
		ia=new ImageArray();
		JButton test=new JButton("Test");
		getContentPane().add(test);
		test.addActionListener(new ButtonH());
	}
	public static int test()
	{
		MyVeryFirstFrame mvff=new MyVeryFirstFrame();
		mvff.show();
		mvff.pause();
		return mvff.x;
	}
	public synchronized void pause()
	{
		try
		{
			wait();
		}
		catch(InterruptedException e)
		{
		}
	}
	class ButtonH implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			release();
		}
	}
	public synchronized void release()
	{
		notify();
	}
	public static void main(String [] args)
	{
		JFrame frame=new MyVeryFirstFrame();
		frame.show();
	}
}

--Chessbot
 
that wasn't the program i am using, just a sample. specifically, i need someone to choose one of 35 images and have the frame return the number they selected.

--Chessbot
 
So the actionListener in the ImageChooserFrame need's to know the major Frame, to tell it, when a valid Image was choosen.

When the MajorFrame creates the ImageChooserFrame, it may handle it a reference to itself (this), and the ImageChooserFrame can save it, to use it in the actionListener.

seeking a job as java-programmer in Berlin:
 
thanks, i'll see if that works out

--Chessbot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top