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 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=0;
private int array[]=new int[24];
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");
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]);
formatter8.format("%d",Page);
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);
ButtonHandler handler=new ButtonHandler();
nextJButton.addActionListener(handler);
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//page always stays at 0, will not move to one and thus display in the label as 1. Page is given the value 0 above, yet I increment it so that it will go to one when the button is pressed//
Page++;
if (Page==1)
{
label1.setText(formatter5.toString());
label2.setText(formatter6.toString());
label3.setText(formatter7.toString());
label10.setText("");
label10.setText(formatter8.toString());
}
else
{
label10.setText("");
label10.setText(formatter8.toString());
}
}
}
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)
{
}
}
import javax.swing.JFrame;
public class RunnableDataEntryTest
{
public static void main(String args[])
{
RunnableDataEntry runnabledataEntry = new RunnableDataEntry();
runnabledataEntry.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
runnabledataEntry.setSize(500,500);
runnabledataEntry.setVisible( true );
}
}