import java.util.Vector;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.util.Formatter;
import java.util.Random;
public class RunnableDataEntry extends JFrame implements FocusListener,KeyListener,ActionListener
{
private JButton nextJButton;
private JButton previousJButton;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JLabel label10;
private JPanel Panel1;
private JPanel Panel2;
private JPanel Panel3;
private JPanel Panel4;
private JPanel Panel5;
private BorderLayout layout;
private GridLayout gridLayout1;
private FlowLayout flowLayout1;
private int Page;
private int array[]=new int[24];
//private int array[]=new int[2];
Formatter formatter=new Formatter();
Formatter formatter2=new Formatter();
Formatter formatter3=new Formatter();
Formatter formatter4=new Formatter();
Formatter formatter5=new Formatter();
Formatter formatter6=new Formatter();
Formatter formatter7=new Formatter();
Formatter formatter8=new Formatter();
public RunnableDataEntry()
{
super("Runnable Data Entry");
layout = new BorderLayout(5,10);
nextJButton=new JButton("Next Page");
previousJButton=new JButton("Previous Page");
flowLayout1= new FlowLayout();
setLayout(layout);
Panel1 = new JPanel();
Panel2=new JPanel();
Panel3=new JPanel();
Random randomNumber=new Random();
for(int counter=0;counter<array.length;counter++)
{
array[counter]=randomNumber.nextInt(10);
}
formatter.format("%d%d%d%d",array[0],array[1],array[2],array[3]);
formatter2.format("%d%d%d%d",array[4],array[5],array[6],array[7]);
formatter3.format("%d%d%d%d",array[8],array[9],array[10],array[11]);
formatter5.format("%d%d%d%d",array[12],array[13],array[14],array[15]);
formatter6.format("%d%d%d%d",array[16],array[17],array[18],array[19]);
formatter7.format("%d%d%d%d",array[20],array[21],array[22],array[23]);
label1=new JLabel(formatter.toString());
label2=new JLabel(formatter2.toString());
label3=new JLabel(formatter3.toString());
label10=new JLabel(formatter8.toString());
add(Panel3,BorderLayout.WEST);
Panel3.add(label10);
add(Panel1,BorderLayout.NORTH);
Panel1.setLayout(flowLayout1);
Panel1.add(label1);
Panel1.add(label2);
Panel1.add(label3);
add(Panel2,BorderLayout.SOUTH);
Panel2.add(nextJButton);
Panel2.add(previousJButton);
ButtonHandler handler=new ButtonHandler();
nextJButton.addActionListener(handler);
previousJButton.addActionListener(handler);
label10.setText("");
String labelText = ( "Page number: " + (Page+1) );
label10.setText( labelText );
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
label10.setText("");
Page++;
Object src=e.getSource();
System.out.printf("%d",Page);
if(src==nextJButton) //this button works fine
{
if (Page==1)
{
label1.setText(formatter5.toString());
label2.setText(formatter6.toString());
label3.setText(formatter7.toString());
String labelText = ( "Page number: " + (Page+1) );
label10.setText( labelText );
}
else
{
label1.setText(formatter5.toString());
label2.setText(formatter3.toString());
label3.setText(formatter7.toString());
String labelText = ( "Page number: " + (Page+1) );
label10.setText( labelText );
}
}
if(src==previousJButton)//here is the problem button
{
label10.setText("");
Page--;
String labelText = ( "Page number: " + (Page+1) );
label10.setText( labelText );
}
}
}
public void focusGained(FocusEvent e)
{
}
public void focusLost(FocusEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e) {
}
public void actionPerformed(ActionEvent event)
{
}
}