naruto9's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
23 (0.02 per day)
Joined:
06-November 12
Profile Views:
543
Last Active:
User is offline Mar 13 2016 08:10 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   naruto9 has not set their status

Posts I've Made

  1. In Topic: Trouble with Thread.sleep() to Timer conversion on JApplet

    Posted 8 Jul 2014

    Yeah, I was aware of the typo and I did reproduce it XD.

    Im very rusty on event listener but this is my code after cleaning up a bit:

    Is it possible you could show me how i can make 'fetchUrl()' run every 6 seconds using timer?
    //imports not shown for brevity
    
    public class NamecSub extends JApplet implements ActionListener {
    	int DELAY = 6000;
                                                                    //can ignore these
    	JLabel question = new JLabel("Enter name to check: ");
    	JLabel question2 = new JLabel("Check how long? (in minutes)");
    	JLabel result = new JLabel("Status");
    	JTextField resp = new JTextField(12);
    	JTextField timeLength = new JTextField(5);
    	JButton enter = new JButton("Check Availability");
    	//JButton reset = new JButton("Reset Fields");
    	Font tnr = new Font("TimesRoman", Font.PLAIN, 20);
    	Color forum = new Color(17, 26, 45);
    	FlowLayout flow = new FlowLayout();
    	Container c;
    	JPanel test = new JPanel(new BorderLayout());
    	Timer t;                                        //declare Timer t
    	URL rsUrl;
    	BufferedReader br;
    	
    	public void init() {
    		
    		c = getContentPane();
    		c.setLayout(flow);
    		c.setBackground(forum);	
    		
    		question.setForeground(Color.white);
    		question.setFont(tnr);	
    		question2.setForeground(Color.white);
    		question2.setFont(tnr);
    		result.setForeground(Color.white);
    		result.setFont(tnr);	
    		resp.setBorder(BorderFactory.createBevelBorder(0));
    		timeLength.setBorder(BorderFactory.createBevelBorder(0));
    		c.add(question);	
    		c.add(resp);
    		c.add(question2);
    		c.add(timeLength);
    		c.add(enter);
    		c.add(result);
    		resp.requestFocus();
    		enter.addActionListener(this);
    		t = new Timer(DELAY, this);               //is this right?
    	}
    	public void actionPerformed(ActionEvent e) {
    		final String n1;
    		int timeMin, timeSec, count = 0, maxCount;
    		if (e.getSource() == enter) {	
    			timeMin = Integer.parseInt(timeLength.getText());
    			timeSec = timeMin * 60;
    			maxCount = (int)(timeSec/6);
    			n1 = resp.getText();
    			while (count < maxCount) {
    				fetchUrl(n1);                       //just want this method to run every 6 seconds
    				t.start();
    				count++;
    			}	
    		}
    	}
    	public void fetchUrl(String name) {
    		//not shown for brevity	
    }
    
    
  2. In Topic: Trouble with Thread.sleep() to Timer conversion on JApplet

    Posted 8 Jul 2014

    I'm not sure what other route to take to put it in a webpage. I made an applet because its not too big of a project I'm doing.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

naruto9 hasn't added any friends yet.

Comments

naruto9 has no profile comments yet. Why not say hello?