난 아무것도 할 시작되기 전에 유엔 - 감동 모든 코드는, 내가 조금 부정한 알고하지만 난 정말 죄송합니다 ...이 프로젝트를 완료하기 위해 서두르고있어 그것 때문에입니다
메인 GUI 클래스 : 변수 :
private static final long serialVersionUID = 1L;
float fval=0;
XBee xbee = new XBee();
XBeeResponse response;
JFrame MainFrame;
JTextField OnOff;
JTable datafield0, datafield1;
JComboBox<String> Dropdown;
Filer outputFile = new Filer();
XBeeDecoder decode = new XBeeDecoder();
CardLayout card = new CardLayout();
String[] FileNames = new File("C:/File Database/").list();
Queue<XBeeResponse> ConvertingQueue = new LinkedList<XBeeResponse>();
Queue<XBeeResponse> Rqueue = new LinkedList<XBeeResponse>();
DecimalFormat formatfloat = new DecimalFormat("0.000");
JButton XBee, Data, Graph, Pdata;
이전 데이터 패널 :
public void MakePreviousDataPanel()
{
PdataBack.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Dropdown = new JComboBox<String>(FileNames);
Dropdown.addItemListener(this);
gbc.gridy=0;
gbc.ipady=15;
gbc.ipadx=30;
PdataBack.add(Dropdown,gbc);
gbc.gridy=1;
gbc.ipady=20;
PdataBack.add(CreateLabel("Accel X Accel Y Accel Z Gyro X Gryo Y Gryo Z Temp Air Pressure Alititude Latitude Longitude"), gbc);
datafield1= new JTable(15,11);
datafield1.setAutoscrolls(true);
datafield1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
datafield1.setDragEnabled(true);
datapanel1.setSize(700,500);
datapanel1.add(datafield1);
gbc.gridy=2;
gbc.ipady=25;
gbc.gridheight=1;
PdataBack.add(datafield1, gbc);
gbc.gridy=3;
gbc.gridheight=1;
gbc.ipady=10;
PdataBack.add(backbutton,gbc);
}
,451,515,
은의 actionPerformed :
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == XBee)
{
if(xbee.isConnected()==true)
{
OpenCloseXBee(0);
OnOff.setText("XBee is Off");
}
else
{
OpenCloseXBee(1);
OnOff.setText("XBee is On");
}
}
if(event.getSource() == Data)
{
card.show(MainBack, "Data");
//System.out.println("Values in queue: "+ ConvertingQueue.size());
outputFile.responses.addAll(ConvertingQueue);
System.out.println("Responses in queue: "+ Rqueue.size());
outputFile.filecounter= new File("C:/File Database/").listFiles().length;
outputFile.filecounter++;
outputFile.filename="C:/File Database/data"+outputFile.filecounter+".txt";
outputFile.CreateFile();
outputFile.ConvertToFloat();
outputFile.WriteHeader();
outputFile.WriteData();
if(xbee.isConnected() == false)
{
if(ConvertingQueue.isEmpty()==false)
{
for(int i=0; i< datafield0.getRowCount(); i++)
{
for(int j=0; j< datafield0.getColumnCount(); j++)
{
fval= decode.processfloat(ConvertingQueue.poll());
formatfloat.format(fval);
datafield0.setValueAt(fval,i,j);
}
}
}
}
}
if(event.getSource() == Graph)
{
card.show(MainBack, "GraphBack");
}
if(event.getSource() == Pdata)
{
card.show(MainBack, "Previous Data");
}
if(event.getSource()==choose)
{
int showOpenDialog = chooseFile.showOpenDialog(getParent());
if(showOpenDialog == 0) {
File selectedFile = chooseFile.getSelectedFile();
model.updateTableData(selectedFile);
}
}
if(event.getSource()==back)
{
card.show(MainBack, "Main");
}
}
마지막 파일러 클래스되지 최소 :
package com.rapplogic.xbee.examples.wpan;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.rapplogic.xbee.api.*;
public class Filer
{
//Use PrintWriter to Open/Close File and use FileWriter to write/read to file
String filename;
int filecounter;
Queue<XBeeResponse> responses = new LinkedList<XBeeResponse>();
LinkedList<Float> fvals = new LinkedList<Float>();
ArrayList<Float> filedata = new ArrayList<Float>();
DataOutputStream RunOutput;
FileOutputStream Filewrite;
String newline = System.getProperty("line.separator");
XBeeDecoder decode = new XBeeDecoder();
File fileread;
Scanner Reader;
public Filer()
{
//filename = "C:/File Database/data"+filecounter;
}
public static void main (String[] args) throws IOException //Main Method Close the file here after operations finish
{
//Test Block DO NOT USE test block to only be used with file data0
Filer data = new Filer();
data.filename= "C:/File Database/data12.txt";
data.ReadData();
//data.CreateFile();
//data.WriteHeader();
//data.WriteData();
//data.RunOutput.close();
}
public void CreateFile()
{
try
{
this.Filewrite = new FileOutputStream(this.filename, false);
this.RunOutput = new DataOutputStream(Filewrite);
System.out.println("File Created");
}
catch (IOException e)
{
System.out.println("File Not Opened/Not Created");
System.out.println(e.getMessage());
}
}
public void ConvertToFloat()
{
float fval=0;
int size=responses.size();
for(int i=0; i< size; i++)
{
fval= decode.processfloat(responses.poll());
fvals.add(fval);
}
}
public void WriteData()
{
String fString=null;
try
{
while(fvals.isEmpty()==false)
{
if(fvals.peek() !=555)
{
fString= Float.toString(fvals.poll());
RunOutput.writeBytes(fString+",");
}
else
{
RunOutput.writeBytes(newline);
fvals.remove();
}
}
}
catch(IOException e)
{
System.out.println("File not written to");
}
System.out.println("Wrote data to file");
}
public void WriteHeader()
{
try
{
RunOutput.writeBytes("Accel X,Accel Y,Accel Z,Gyro X,Gryo Y,Gryo Z,Temp,Air Pressure,Alititude,Latitude,Longitude");
RunOutput.writeBytes(newline);
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
public void ReadData()
{
fileread = new File(filename);
System.out.println(this.filename);
try
{
Reader = new Scanner(fileread);
Reader.nextLine();
String text="";
while(Reader.hasNext())
{
text+= Reader.nextLine();
}
System.out.println(text);
String[] collected = text.split(",");
for(int temp=0; temp<collected.length; temp++)
{
this.filedata.add(Float.parseFloat(collected[temp]));
//System.out.println(temp);
}
System.out.println("Filer Array list size:" + this.filedata.size());
/*for(int temp=0; temp< filedata.size(); temp++)
System.out.println(filedata.get(temp)); */
}
catch (FileNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(NumberFormatException num)
{
System.out.println("No Numbers found/ Cannot format values");
}
}
public List<Collection> ReadData(final File file) {
List<Collection> data = new ArrayList<>();
if(!file.isDirectory() && file.canRead()) {
try {
BufferedReader br = new BufferedReader(new FileReader(file));
br.readLine();
String line = "";
while((line = br.readLine()) != null) {
String[] split = line.split(",");
Collection dff = new Collection(Float.parseFloat(split[0]),Float.parseFloat(split[1]),Float.parseFloat(split[2]),Float.parseFloat(split[3]),Float.parseFloat(split[4]),Float.parseFloat(split[5]),
Float.parseFloat(split[6]),Float.parseFloat(split[7]),Float.parseFloat(split[8]),Float.parseFloat(split[9]),Float.parseFloat(split[10]));
data.add(dff);
}
System.out.println("Reading from file finished");
br.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(PreviousTableModel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(PreviousTableModel.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("Sorry, i can not read your input file!");
}
return data;
}
@SuppressWarnings("null")
public List<Collection> SortData(ArrayList<Float> RawData)
{
List<Collection> sortedData = null;
while(RawData.isEmpty() ==false)
{
Collection fullCollect =new Collection(RawData.get(0),RawData.get(1),RawData.get(2),RawData.get(3),RawData.get(4),RawData.get(5),
RawData.get(6),RawData.get(7),RawData.get(8),RawData.get(9),RawData.get(10));
for(int i=0; i<11;i++)
RawData.remove(0);
sortedData.add(fullCollect);
}
return sortedData;
}
public class Collection
{
float AccelX,AccelY,AccelZ,GyroX,GyroY,GyroZ,
Temp,AirPressure,Altitude,Latitude,Longitude;
public Collection(final float AccelX, final float AccelY, final float AccelZ, final float GyroX, final float GyroY,
final float GyroZ, final float Temp, final float AirPressure, final float Altitude, final float Latitude, final float Longitude)
{
this.AccelX= AccelX;
this.AccelY=AccelY;
this.AccelZ=AccelZ;
this.AirPressure= AirPressure;
this.Altitude=Altitude;
this.GyroX=GyroX;
this.GyroY=GyroY;
this.GyroZ=GyroZ;
this.Latitude=Latitude;
this.Longitude=Longitude;
this.Temp=Temp;
}
public float getAccelX() {
return AccelX;
}
public void setAccelX(float accelX) {
AccelX = accelX;
}
public float getAccelY() {
return AccelY;
}
public void setAccelY(float accelY) {
AccelY = accelY;
}
public float getAccelZ() {
return AccelZ;
}
public void setAccelZ(float accelZ) {
AccelZ = accelZ;
}
public float getGyroX() {
return GyroX;
}
public void setGyroX(float gyroX) {
GyroX = gyroX;
}
public float getGyroY() {
return GyroY;
}
public void setGyroY(float gyroY) {
GyroY = gyroY;
}
public float getGyroZ() {
return GyroZ;
}
public void setGyroZ(float gyroZ) {
GyroZ = gyroZ;
}
public float getTemp() {
return Temp;
}
public void setTemp(float temp) {
Temp = temp;
}
public float getAirPressure() {
return AirPressure;
}
public void setAirPressure(float airPressure) {
AirPressure = airPressure;
}
public float getAltitude() {
return Altitude;
}
public void setAltitude(float altitude) {
Altitude = altitude;
}
public float getLatitude() {
return Latitude;
}
public void setLatitude(float latitude) {
Latitude = latitude;
}
public float getLongitude() {
return Longitude;
}
public void setLongitude(float longitude) {
Longitude = longitude;
}
}
}
표 모델 :
package com.rapplogic.xbee.examples.wpan;
import java.io.File;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import com.rapplogic.xbee.examples.wpan.Filer.Collection;
public class PreviousTableModel extends AbstractTableModel
{
private static final long serialVersionUID = 1L;
private final String[] columnNames={"AccelX", "AccelY","AccelZ","GyroX","GyroY","GryoZ","Temp","Air Pressure","Altitude","Latitude","Longitude"};
Filer tableFile = new Filer();
List<Collection> allCollections;
public PreviousTableModel()
{
}
@Override
public int getColumnCount()
{
return columnNames.length;
}
@Override
public int getRowCount()
{
return allCollections.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Collection value = allCollections.get(rowIndex);
switch(columnIndex) {
case 0:
return value.getAccelX();
case 1:
return value.getAccelY();
case 2:
return value.getAccelZ();
case 3:
return value.getGyroX();
case 4:
return value.getGyroY();
case 5:
return value.getGyroZ();
case 6:
return value.getTemp();
case 7:
return value.getAirPressure();
case 8:
return value.getAltitude();
case 9:
return value.getLatitude();
case 10:
return value.getLongitude();
}
return null;
}
public String getColumnName(int column) {
return columnNames[column];
}
public void updateTableData(File selectedFile) {
allCollections = tableFile.ReadData(selectedFile);
System.out.println("Changing table");
fireTableDataChanged();
}
}
그래서이 내가 가진 모든 코드를 테이블 모델이나 중요한 변경을하기 전에다시 정말 당신이 패트 릭 도움이 돼 주셔서 감사합니다 모든 데이터를 저장할 수있는 내부 클래스를 시도하고 지저분한 코드에 대해 다시 감사드립니다 및 미안 해요 참조하십시오 :)
나는 'itemStateChange) '메소드 – TeamIncredibles
'setValueAt'에서'yourTableVariable.revalidate()'를 시도 했습니까? 레이아웃을 다시 작성하거나 다시 칠할 필요가 없을 수도 있습니다. – DankMemes
'public void setValueAt (Object value, int row, int col) \t { \t \t rowData [row] [col] = (Float) value; \t \t guitable.datafield1.revalidate(); \t \t //this.fireTableCellUpdated(row, col); \t \t \t} ' 편집을했지만 스택에 오버로드가 발생했습니다. 또한 tableChanged를 구현하려고했지만 실제로 데이터를 가져 와서 테이블에 넣는 작업을 모릅니다. @TeamIncredible 어떤 종류 또는 의심 당신은 내가 그것에 대해 뭔가 할 수 있을지 모르겠다 – UP2ME4ME