import java.awt.image.BufferStrategy;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
public class flicker extends JFrame {
JTable table;
DefaultTableModel model = new DefaultTableModel();
JButton Acknowledge;
JPanel Panel=new JPanel();
JScrollPane Pane;
JScrollPane Pane1;
JScrollPane Pane2;
String[] Optlist = {"Show Alarm", "Show History", "Report Alarm (PDF)", "Report History (PDF)"};
JComboBox Options=null;
BufferStrategy myStrategy;
String p=null;
String w=null;
String area=null;
int i,r;
String ip,selection,stso,group,message,p1,p2,Sensor;
static String checkedval;
static String Name;
Double Value;
Object data[][]=null;
public flicker(String string) {
super(string);
Panel.setLayout(null);
getContentPane().add(Panel);
start();
Pane=new JScrollPane(table);
Pane.setSize(500,500);
Pane1=new JScrollPane(Acknowledge);
Pane1.setSize(90,30);
Pane1.setBounds(0,500,320,30);
Pane2=new JScrollPane(Options);
Pane2.setBounds(320,500,180,30);
Panel.add(Pane);
Panel.add(Pane1);
Panel.add(Pane2);
setSize(520,570);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
private void start()
{
try
{
final Scanner sc = new Scanner(System.in);
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>()
{
@Override
protected Object doInBackground()
{
System.out.println("Write message here: ");
message=sc.nextLine();
System.out.println("Message is: "+message);
Object col[] = {"Sensor","Values","Arrival_Time","Status",""};
if(!message.equals("ITS EMPTY"))
{
String[] parts = message.split("\t");
data = new Object[parts.length / 4][5];
for (i = 0, r = 0; r < data.length; r++)
{
data[r][0] = parts[i++];
//data[r][1] = new Double(parts[i++]) ;
data[r][1] = parts[i++] ;
data[r][2] = parts[i++];
data[r][3] = parts[i++];
p=(String) data[r][3];
w = (String) abc(p);
data[r][4]=Boolean.parseBoolean(w) ;
System.out.println(data[r][4]);
}
//System.out.println(java.util.Arrays.deepToString(data));
//Display Table
model.setDataVector(data, col);
table = new JTable(model)
{
private static final long serialVersionUID = 1L;
@Override
public Class getColumnClass(int column)
{
switch (column) {
case 0:
return String.class;
case 1:
return String.class;
case 2:
return String.class;
case 3:
return String.class;
default:
return Boolean.class;
}
}
};
publish(table);
}
else
{
System.out.println("NO TABLE");
}
return table;
}
protected void process(JTable table)
{
// table.setDefaultRenderer(Object.class, new CustomTableCellRenderer3());
// table.setPreferredScrollableViewportSize(table.getPreferredSize());
// table.getColumnModel().getColumn(4).setCellEditor(new CustomTableCellRenderer(new JCheckBox(),Name));
model.fireTableDataChanged();
table.repaint();
}
};
worker.execute();
}
catch(Exception e)
{
System.out.println("Exception Occured:" +e);
}
}
private Object abc(String p)
{
String val=null;
if(p.equals("ACK"))
{
val="true";
}
else if(p.equals("nil"))
{
val="false";
}
return val;
}
}