Trouble reading user input in Mac OSX

Advertisement
November 30

Hi, I am writing a program in Java (1.5) for Mac OSX that requires the user to setup files and settings, then a new frame opens with a blank screen and waits for user input (a key press) to begin. I have a setup screen that works fine (seperate frame) and triggers the blank screen and the rest of the program fine as well. The problem is when I try to have the program pause for user input. For some reason, this thread is no longer responding to user input at all. I have tried with a KeyListener Interface and with System.in.read() as well as BufferedReaders, etc and there are no keypresses registered at all.
Another object does create a seperate thread to deal with closing down Quicktime elements, but the keypresses are not registering even when that thread has not been called.
Can anyone tell me what might be the problem? Is there an issue with multiple frames interfering with the KeyListener? I can post the code, if you'd like, but it's pretty involved.
Any help greatly appreciated!
Heidi

Advertisement

Replay

Actually, this still isn't working. I'm posting the program class (there are several supporting classes that are not in this post - SetUp opens a SetUp frame and gathers information, then calls MTSNewSwing. Start movie places a Quicktime Component into a Panel, and QTSessionCheck starts a thread that check to make sure that QT sessions are closed when neccessary). KeyPresses are stll not being registered at all.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import quicktime.*;
import quicktime.std.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
public class MTSNewSwing extends JFrame{
     public Insets getInsets() {
          Insets rm = new Insets (20, 20, 20, 20);
          return rm;
char key = 'q';
int correct = 0;
boolean kp = false;
int numberOfMovies;
ArrayList<File> moviesList = new ArrayList();
ArrayList<File> altList = new ArrayList();
     public MTSNewSwing() {
          super("Matching to Sample");
          setSize(1024, 768);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setBackground(Color.black);
          getRootPane().registerKeyboardAction(new ActionListener(){
               public void actionPerformed(ActionEvent e) {
               System.out.println("keystroke"); }
          },KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),JComponent.WHEN_IN_FOCUSED_WINDOW);
          moviesList = SetUp.movieList;
          numberOfMovies = moviesList.size();
          int randomSampleIndex;
          int randomAlternativeIndex;
          boolean corrAltAdded = false;
          //run new trial through numOfTrials
          for (int t = 0; t < SetUp.numOfTrials; t++) {
               //clear screen
               BlankScreen bs = new BlankScreen();
               getContentPane().add(bs);
               setVisible(true);
               //put random alternatives into array list
               randomSampleIndex = (int) (Math.random() * SetUp.numOfMovies);
               File sample = (File) moviesList.get(randomSampleIndex);
               altList.add(sample);
               int correctAlternativePosition = (int) (Math.random() * SetUp.numOfAlternatives);
               for (int altPosition = 1; altPosition <= SetUp.numOfAlternatives; altPosition++) {
                    if (altPosition == correctAlternativePosition) {
                         altList.add(sample);
                         corrAltAdded = true;
                         System.out.println("correct alternative added");
                    } else if (altPosition == SetUp.numOfAlternatives && corrAltAdded == false) altList.add(sample);
                    else {
                         do {
                              randomAlternativeIndex = (int) (Math.random() *
SetUp.numOfMovies);
                         } while (randomAlternativeIndex == randomSampleIndex);      
                         File nextAlt = (File) moviesList.get(randomAlternativeIndex);
                         altList.add(nextAlt);
                         System.out.println("alternative added");
               corrAltAdded = false;
               //wait for keypress to start trial
          //this is the part that still doesn't work
               //add movies to screen
               for (int i=0; i<= SetUp.numOfAlternatives; i++) {
                    File file = (File) altList.get(i);
                    StartMovie sm = new StartMovie();
                    try {
                         sm.go(file);
                    } catch (Exception e) {
                         e.printStackTrace();
                    if (SetUp.numOfAlternatives < 4) {
                         BorderLayout bdr = new BorderLayout();
                         this.setLayout(bdr);
                         JPanel samp = new JPanel();
                         JPanel alts = new JPanel();
                         BorderLayout altbdr = new BorderLayout();
                         alts.setLayout(altbdr);
                         if (i ==0) {
                              samp.add(sm);
                              this.getContentPane().add(samp, BorderLayout.NORTH);
                              setVisible(true);
                              System.out.println("sample added");
                         } else if (i == 1) {
                              alts.add(sm, BorderLayout.WEST);
                              System.out.println("alt1 added");
                         } else if (i == 2) {
                              alts.add(sm, BorderLayout.EAST);
                              System.out.println("alt2 added");
                         } else if (i == 3) {
                              alts.add(sm, BorderLayout.CENTER);
                              System.out.println("alt3 added");
                         this.getContentPane().add(alts, BorderLayout.SOUTH);
                         setVisible(true);
                         try {
                              Thread.sleep(10000);
                         } catch (InterruptedException ex) {
                              ex.printStackTrace();
                         continue;
     public static void main(String args[]) {
               SetUp setup = new SetUp();
}

View 15 Replies

Tags:

  1. PARNR LiVE ViDEo ON
  2. logic 9 for windows 7 200mbs
  3. sapjco3 Connect to SAP gateway failed
  4. how to set program run dat in rffoedi1
  5. highesta4n
  6. swimmingxgn
  7. officialwv4
  8. whateverebb
  9. 2K38
  10. grainoh6
Copyrights 2019 Fcffair BigData Resource, All rights reserved