/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package imagegame; import java.awt.Font; import java.awt.GridLayout; import java.util.TimerTask; import java.util.Timer; import javax.swing.*; /** * * @author ruhuayan */ public class TimeJPanel extends JPanel { private final JLabel nameJLabel; //private final JLabel timeJLabel; private final JTextField timeJTField; private int mm = 0; private int ss = 0; private Timer timer; private final TimerTask task; private final JButton hintJButton; private final JButton pictJButton; public TimeJPanel(){ initComponents(); setLayout(new GridLayout(1,4)); nameJLabel = new JLabel("VISITOR"); nameJLabel.setFont(new Font("Courier", Font.BOLD,14)); //nameJLabel.setVerticalAlignment(SwingConstants.CENTER); add(nameJLabel); //timeJLabel = new JLabel("Timer: "); //timeJLabel.setHorizontalAlignment(SwingConstants.RIGHT); // add(timeJLabel); //timeJLabel.setFont(new Font("Courier", Font.BOLD,14)); timeJTField = new JTextField(); timeJTField.setFont(new Font("Courier", Font.BOLD,14)); timeJTField.setEditable(false); add(timeJTField); hintJButton = new JButton("Hint"); add(hintJButton); task = new TimerTask() { @Override public void run() { ss++; if(ss>=60) {mm++; ss=00;} setTimerText(mm,ss); } }; scheduleTimer(); pictJButton = new JButton("Image"); add(pictJButton); } public void reTimer(){ //timer.cancel(); mm=0; ss=0; } public final void scheduleTimer(){ timer = new Timer(); timer.schedule(task, 1000l, 1000L); } public void setJLabelName(String n){ nameJLabel.setText(""+n.toUpperCase()); } public String getJLabelName(){ return nameJLabel.getText(); } public final void setTimerText(int m,int s){ timeJTField.setText(((m<10)?" 0":" ")+ m+((s<10)?" :0":" :")+s ); } public String getTimerText(){ return timeJTField.getText(); } public JButton getHintJButton(){ return hintJButton; } public JButton getPictJButton(){ return pictJButton; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }