我知道這個信息無處不在,但其如此巨大的難以選擇合適的方法。所以即使指着我正確的地方也適用。儲存大量的表格/模式
我開發的軟件,他輸入自己的股票交易客戶端和它的各種數據輸出到一個表。沒有任何訪問的股票數據,這是全部內部的,僅供個人使用。
我堅持的是什麼,他希望能夠通過週一洗牌至週五,或視圖從一年前的輸入數據。那麼我將如何存儲每日表格數據。
我應該表的模型保存到一個文件或數據庫?也許有一種我不知道的方法。
的表是10列寬有大約900排很長,如果該事項對任何人。
編輯*
解答這裏更多的代碼的要求是什麼,我已經打破down.`
MainFrame() {
super("Stack Overflow Stock Software");
model.addColumn("Exchange");
model.addColumn("Inv/Sec");
model.addColumn("Name");
model.addColumn("Qty");
// model.addColumn("Fd");
model.addColumn("Average Cost");
model.addColumn("Market");
model.addColumn("Balance");
// model.addColumn("Interest");
model.addColumn("Today's PL");
model.addColumn("Total Pl");
// model.addColumn("Multiplier");
// model.addRow(data);
table = new JTable(model);
modelTotal.addColumn("Balance");
modelTotal.addColumn("Today PL");
modelTotal.addColumn("Total PL");
table2 = new JTable(modelTotal);
setLayout(new BorderLayout());
// JComboBox<String> comboBox = new JComboBox<>(exchangeStrings);
// sorter = new TableRowSorter<TableModel>(table.getModel());
JPanel panel1 = new JPanel();
text1 = new JTextField(5);
text1.setText("ABA");
text1.setHorizontalAlignment(SwingConstants.CENTER);
text2 = new JTextField(12);
text2.setText("1000");// quanity
text2.setHorizontalAlignment(SwingConstants.CENTER);
text3 = new JTextField(10);
text3.setText("10.00");// price
text3.setHorizontalAlignment(SwingConstants.CENTER);
button1 = new JButton("Buy");
button1.addActionListener(this);
button2 = new JButton("Sell");
button2.addActionListener(this);
JScrollPane scrollPane = new JScrollPane(table);
JScrollPane scrollPane2 = new JScrollPane(table2);
// sets table settings
table.setFillsViewportHeight(true);
table.getColumnModel().getColumn(0).setMaxWidth(80);
table.getColumnModel().getColumn(1).setPreferredWidth(80);
table.getColumnModel().getColumn(2).setPreferredWidth(180);
table.getColumnModel().getColumn(4).setPreferredWidth(24);
table.getColumnModel().getColumn(6).setPreferredWidth(24);
table.getColumnModel().getColumn(7).setPreferredWidth(24);
// table.getColumnModel().getColumn(9).setPreferredWidth(0);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
setCellsAlignment(table, SwingConstants.CENTER);
setCellsAlignment(table2, SwingConstants.CENTER);
// add panels/buttons/etc to page
add(panel1, BorderLayout.PAGE_START);
panel1.setPreferredSize(new Dimension(1280, 50));
add(scrollPane, BorderLayout.CENTER);
add(scrollPane2, BorderLayout.PAGE_END);
scrollPane2.setPreferredSize(new Dimension(1280, 50));
// add(scrollPane, BorderLayout.CENTER);
panel1.add(comboBox, BorderLayout.SOUTH);
panel1.add(text1, BorderLayout.SOUTH);
panel1.add(text3, BorderLayout.SOUTH);// price
panel1.add(text2, BorderLayout.SOUTH);
panel1.add(button1, BorderLayout.NORTH);
panel1.add(button2, BorderLayout.NORTH);
setMenuBar();
modelTotal.addRow(data2);
setExtendedState(MAXIMIZED_BOTH);
setMinimumSize(new Dimension(1280, 485));
setSize(640, 485);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private void setMenuBar() {...}
/*Set the menu bar up*/
public static void setCellsAlignment(JTable table, int alignment) {
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(alignment);
TableModel tableModel = table.getModel();
for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) {
table.getColumnModel().getColumn(columnIndex).setCellRenderer(rightRenderer);
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {// if button 1 pressed to buy
purchaseMade = true;
// input data in data object for adding or combining.
String comboString = comboBox.getSelectedItem().toString();
String stringCombo = comboString;
data[0] = stringCombo;
data[1] = text1.getText();
data[2] = text1.getText(); // turn into long string
data[3] = text2.getText();// quanity
data[5] = text3.getText();// price
data[4] = text3.getText();// average market price
double String1 = Double.parseDouble(data[3].toString());
double String2 = Double.parseDouble(data[4].toString());
data[6] = String1 * String2;
double dataQuanity = Double.parseDouble(data[3].toString());
double dataPrice = Double.parseDouble(data[4].toString());
data[7] = dataQuanity * dataPrice * -1;
data[8] = dataQuanity * dataPrice * -1;
data[4] = Double.parseDouble(data[4].toString());
data[4] = df.format(data[4]);
data[5] = Double.parseDouble(data[5].toString());
data[5] = df.format(data[5]);
data[6] = Double.parseDouble(data[6].toString());
data[6] = df.format(data[6]);
data[7] = Double.parseDouble(data[7].toString());
data[7] = df.format(data[7]);
data[8] = Double.parseDouble(data[8].toString());
data[8] = df.format(data[8]);
// add data and continue on
model.addRow(data);
dataCount++;
combineData(model);
sortData(table);
}
if (e.getSource() == button2) {
purchaseMade = false;
// input data in data object for adding or combining.
data[0] = comboBox.getSelectedItem();// exchange
data[1] = text1.getText();// symbol
data[2] = text1.getText(); // turn into long string//name
data[3] = text2.getText();// quanity
data[4] = text3.getText();// average price
data[5] = text3.getText();// closing bid/market
data[9] = 1;
// data 5 can wait
double String1 = Double.parseDouble(data[3].toString());
double String2 = Double.parseDouble(data[4].toString());
data[6] = String1 * String2;
// pl
double dataQuanity = Double.parseDouble(data[3].toString());
double dataPrice = Double.parseDouble(data[4].toString());
data[7] = dataQuanity * dataPrice * -1;
data[8] = dataQuanity * dataPrice * -1;
// add data and continue on
dataCount++;
combineData(model);
sortData(table);
}
}
private void combineData(DefaultTableModel model2) {
/*This section of codes adds the new data to a table or combines it with a duplicate entry*/
}
private void sortData(JTable table) {...}
/*This is where I sort my table*/
private void calculateLowerData(DefaultTableModel lowerModel, DefaultTableModel dataModel) {...}
/* This is where I calculate a number not relevant to the question*/
private void printTable() {...}
/* This is where I print my data to a table */
}`
要獲得一個答案你需要提供你已經寫的更多細節。徵求意見將讓他鎖定。 –
是的,我之前有問題詢問數據庫問題。發佈我的代碼,儘管我真的是我的數據操作和表/模型/輸入設置。我沒有實現每日輪換,因爲我不知道如何設置要保存的數據。 –