Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Modification of current program to activate notification pop up

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Modification of current program to activate notification pop up

    Hi. Basically, I want my program, if minimized or not the like...active window, to pop-up (I'm pretty sure that is not the technical term, but I don't know what it is). Whenever a new word/phrase changes or it tells you the answer I want it to notify the user somehow. Either by popping itself up to show you, or blink on the bar or something. Is there I can do this without drastically changing the program? Here it is --

    import java.util.ArrayList;
    import java.util.Random;
    public class Library {
     
    	public ArrayList<String> spanish = new ArrayList<String>();		//make a spanish list
    	public ArrayList<String> english = new ArrayList<String>();		//make an english list
    	static Random random = new Random();		//make a random object
    	private int index;
     
    	public void setIndex(int index) {
    		this.index = index;
    	}
     
    	public int getIndex() {
    		return index;
    	}
     
    	//method to add all Strings to the lists
    	public void makeLists() {
    		spanish.add("Cómo se llama?");	english.add("What is his/her name?");
    		spanish.add("Cómo se llama usted?");   english.add("What is your name?");
    		spanish.add("Por favor");		english.add("Please");
    		spanish.add("De dónde eres?");	english.add("Where are you from?");
    		spanish.add("De dónde es usted?");	english.add("Where are you from?(form)");
    		spanish.add("Hasta la vista");	english.add("See you later");
    		spanish.add("Hasta pronto");	english.add("See you soon");
    		spanish.add("Nos vemos");		english.add("See you");
    		spanish.add("Cómo estás?");		english.add("How are you?");
    		spanish.add("Cómo está usted?");	english.add("How are you?(form)");
    		spanish.add("Qué hay de nuevo?");	english.add("What's new?");
    		spanish.add("Qué tal?");		english.add("How are you?");
    		spanish.add("Con permiso");		english.add("Pardon me");
    		spanish.add("Lo siento");		english.add("I'm sorry");
    		spanish.add("No hay de qué");	english.add("You're welcome");
    		spanish.add("De nada");			english.add("You're welcome");
    		spanish.add("Mucho gusto");		english.add("Pleased to meet you");
    		spanish.add("Le presento a...");	english.add("I would like to introduce...");
    		spanish.add("Te presento a...");	english.add("I would like to introduce...(form)");
    		spanish.add("Soy de...");		english.add("I'm from...");
    		spanish.add("Cuántos?");		english.add("How many?");
    		spanish.add("el autobús");		english.add("bus");
    		spanish.add("la capital");		english.add("capital city");
    		spanish.add("el chico");		english.add("boy");
    		spanish.add("la chica");		english.add("girl");
    		spanish.add("la computadora");	english.add("computer");
    		spanish.add("la comunidad");	english.add("community");
    		spanish.add("el/la conductor(a)");	english.add("driver");
    		spanish.add("la conversación");	english.add("conversation");
    		spanish.add("la cosa");			english.add("thing");
    		spanish.add("el cuaderno");		english.add("notebook");
    		spanish.add("el día");			english.add("day");
    		spanish.add("el diario");		english.add("diary");
    		spanish.add("el diccionario");	english.add("dictionary");
    		spanish.add("la escuela");		english.add("school");
    		spanish.add("la grafia");		english.add("photograph");
    		spanish.add("la grabadora");	english.add("tape recorder");
    		spanish.add("el lápiz");		english.add("pencil");
    		spanish.add("la maleta");		english.add("suitcase");
    		spanish.add("la mano");			english.add("hand");
    		spanish.add("la mujer");		english.add("woman");
    		spanish.add("el país");			english.add("country");
    		spanish.add("la palabra");		english.add("word");
    		spanish.add("el/la pasajero/a");	english.add("passenger");
    		spanish.add("bailar");			english.add("to dance");
    		spanish.add("buscar");			english.add("to look for");
    		spanish.add("caminar");			english.add("to walk");
    		spanish.add("cantar");			english.add("to sing");
    		spanish.add("cenar");			english.add("to have dinner");
    		spanish.add("comprar");			english.add("to buy");
    		spanish.add("contestar");		english.add("to answer");
    		spanish.add("conversar");		english.add("to converse");
    		spanish.add("desayunar");		english.add("to have breakfast");
    		spanish.add("descansar");		english.add("to rest");
    		spanish.add("desear");			english.add("to wish");
    		spanish.add("dibujar");			english.add("to draw");
    		spanish.add("enseñar");			english.add("to teach");
    		spanish.add("escuchar");		english.add("to listen");
    		spanish.add("esperar");			english.add("to wait for");
    		spanish.add("estar");			english.add("to be");
    		spanish.add("estudiar");		english.add("to study");
    		spanish.add("explicar");		english.add("to explain");
    		spanish.add("gustar");			english.add("to like");
    		spanish.add("hablar");			english.add("to speak");
    		spanish.add("llegar");			english.add("to arrive");
    		spanish.add("llevar");			english.add("to carry");
    		spanish.add("mirar");			english.add("to look at");
    		spanish.add("necesitar");		english.add("to need");
    		spanish.add("practicar");		english.add("to practice");
    		spanish.add("preguntar");		english.add("to ask");
    		spanish.add("preparar");		english.add("to prepare");
    		spanish.add("regresar");		english.add("to return");
    		spanish.add("terminar");		english.add("to end");
    		spanish.add("tomar");			english.add("to take");
    		spanish.add("trabajar");		english.add("to work");
    		spanish.add("viajar");			english.add("to travel");
    		spanish.add("el/la compañero/a de clase");	english.add("classmate");
    		spanish.add("el/la compañero/a de cuarto");	english.add("roommate");
    		spanish.add("el borrador");		english.add("eraser");
    		spanish.add("el escritorio");	english.add("desk");
    		spanish.add("el libro");		english.add("book");
    		spanish.add("la mesa");			english.add("table");
    		spanish.add("la mochila");		english.add("bookbag");
    		spanish.add("el papel");		english.add("paper");
    		spanish.add("la papelera");		english.add("wastebasket");
    		spanish.add("la pizarra");		english.add("blackboard");
    		spanish.add("la pluma");		english.add("pen");
    		spanish.add("la puerta");		english.add("door");
    		spanish.add("el reloj");		english.add("watch");
    		spanish.add("la silla");		english.add("seat");
    		spanish.add("la tiza");			english.add("chalk");
    		spanish.add("la ventana");		english.add("window");
    		spanish.add("la biblioteca");	english.add("library");
    		spanish.add("la cafetería");	english.add("cafeteria");
    		spanish.add("la casa");			english.add("house");
    		spanish.add("el estadio");		english.add("stadium");
    		spanish.add("la librería");		english.add("bookstore");
    		spanish.add("la residencia estudiantil");	english.add("dormitory");
    		spanish.add("la universidad");	english.add("university");
    		spanish.add("la clase");		english.add("class");
    		spanish.add("el curso, la materia");	english.add("course");
    		spanish.add("la especialización");	english.add("major");
    		spanish.add("el examen");		english.add("test");
    		spanish.add("el horario");		english.add("schedule");
    		spanish.add("la prueba");		english.add("quiz");
    		spanish.add("la tarea");		english.add("homework");
    		spanish.add("la administración");	english.add("business");
    		spanish.add("de empresas");		english.add("administration");
    		spanish.add("las ciencias");	english.add("sciences");
    		spanish.add("la contabilidad");	english.add("accounting");
    		spanish.add("el periodismo");	english.add("journalism");
    		spanish.add("la química");		english.add("chemistry");
    		spanish.add("al lada de");		english.add("next to");
    		spanish.add("a la derecha de");	english.add("to the right of");
    		spanish.add("a la izquierda de");	english.add("to the left of");
    		spanish.add("cerca de");		english.add("near");
    		spanish.add("debajo de");		english.add("below");
    		spanish.add("delante de");		english.add("in front of");
    		spanish.add("detrás de");		english.add("behind");
    		spanish.add("encima de");		english.add("on top of");
    		spanish.add("entre");			english.add("between; among");
    		spanish.add("lejos de");		english.add("far from");
    		spanish.add("sin");				english.add("without");
    		spanish.add("sobre");			english.add("on; over");
    		spanish.add("Adónde?");			english.add("Where (to)?");
    		spanish.add("ahora");			english.add("now");
    		spanish.add("Cuál? Cuáles?");	english.add("Which? Which one?");
    		spanish.add("Por que?");		english.add("Why?");
    		spanish.add("Porque");			english.add("because");
    		spanish.add("Cuándo?");			english.add("When?");
    		spanish.add("Qué día es hoy?");	english.add("What day is it?");
    		spanish.add("la semana");		english.add("week");
    		spanish.add("Lunes");			english.add("Monday");
    		spanish.add("Martes");			english.add("Tuesday");
    		spanish.add("Miércoles");		english.add("Wednesday");
    		spanish.add("Jueves");			english.add("Thursday");
    		spanish.add("Viernes");			english.add("Friday");
    		spanish.add("Sábado");			english.add("Saturday");
    		spanish.add("Domingo");			english.add("Sunday");
     
    	}
     
     
    	//method to grab a word or phrase from the spanish list
    	public String getOne() {
    		int x = random.nextInt(spanish.size());
    		setIndex(x);
    		return spanish.get(getIndex());
    	}	
     
    }

    import javax.swing.*;
    import java.io.*;
     
    import java.util.Random;
     
    public class Player extends Thread{
     
    	private JTextField text;		//make the text field
    	private JTextField input;		//make an input text field	
    	static Library library = new Library();			//make a library object
    	static Random random = new Random();			//make a random object
     
    	public Player() {
    		JFrame frame = new JFrame();
    		JPanel panel = new JPanel();
    		text = new JTextField("Output field", 30);
    		input = new JTextField("Input field", 30);
    		panel.add(text);
    		panel.add(input);
    		frame.add(panel);
    		frame.setVisible(true);
    		frame.pack();
    		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
     
    	}
     
    	public static void main(String args[]) {
    		Player player = new Player();		//make a player
    		library.makeLists();				//make the lists
    		player.start();						//start
     
    	}
     
    	public void run() {
    		try {
    			text.setVisible(true);			//make the field visible
    			boolean loop = true;
    			while(loop) {					//loop forever
    				text.setText(library.getOne() + "\n");		//set the text to a random spanish phrase
    				input.setText("");
    				input.grabFocus();
    				Thread.sleep(5000);			//wait for 5 seconds
    				if(input.getText().equalsIgnoreCase(library.english.get(library.getIndex())))	
    				{
    					text.setText("Right!");		//if i enter in the correct english translation, i'm right
    					Thread.sleep(1000);
    				}
     
    				else { 
    					text.setText("Wrong. The answer is " + library.english.get(library.getIndex()));	//if i'm wrong, display the right answer
    					Thread.sleep(1000);
    				}
    			}	
    		}
    		catch(Exception ex) {
    			ex.printStackTrace();
    		}
     
    	}
     
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Be notified by program?

    Hello Sterzerkmode,

    Yes this is possible and actually very easy. I have made the changes to the Player class, shown in bold.

    When the application is minimized and the word changes, the window pops back up again.

    import javax.swing.*;
    import java.awt.Frame;
    import java.io.*;
    import java.util.Random;
     
    public class Player extends Thread{
     
        private JTextField text;        //make the text field
        private JTextField input;        //make an input text field    
        static Library library = new Library();            //make a library object
        static Random random = new Random();            //make a random object
        [B]public static JFrame frame = new JFrame();[/B]
     
        public Player() {
     
            JPanel panel = new JPanel();
            text = new JTextField("Output field", 30);
            input = new JTextField("Input field", 30);
            panel.add(text);
            panel.add(input);
            frame.add(panel);
            frame.setVisible(true);
            frame.pack();
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
     
        }
     
        public static void main(String args[]) {
            Player player = new Player();        //make a player
            library.makeLists();                //make the lists
            player.start();                        //start
     
        }
     
    [B]    public void setState(){
            frame.setExtendedState(Frame.NORMAL);
        }[/B]
     
     
        public void run() {
            try {
                text.setVisible(true);            //make the field visible
                boolean loop = true;
                while(loop) {                    //loop forever
                    text.setText(library.getOne() + "\n");        //set the text to a random spanish phrase
                    input.setText("");
                    input.grabFocus();
                    Thread.sleep(5000);            //wait for 5 seconds
                    if(input.getText().equalsIgnoreCase(library.english.get(library.getIndex())))    
                    {
                        [B]setState();[/B]
                        text.setText("Right!");        //if i enter in the correct english translation, i'm right
                        Thread.sleep(1000);
                    }
     
                    else { 
                       [B] setState();[/B]
                        text.setText("Wrong. The answer is " + library.english.get(library.getIndex()));    //if i'm wrong, display the right answer
                        Thread.sleep(1000);
                    }
                }    
            }
            catch(Exception ex) {
                ex.printStackTrace();
            }
     
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Tags for this Thread