java swing ui未显示重建的数组索引超出范围
好吧,我还是一个Java新手。老实说,这是一个家庭作业,但我现在正在拼命工作。我不知道从这里到哪里去 我正在为任务编写一个清单程序,它必须使用普通数组。不是java swing ui未显示重建的数组索引超出范围,java,arrays,swing,indexoutofboundsexception,Java,Arrays,Swing,Indexoutofboundsexception,好吧,我还是一个Java新手。老实说,这是一个家庭作业,但我现在正在拼命工作。我不知道从这里到哪里去 我正在为任务编写一个清单程序,它必须使用普通数组。不是ArrayList 我遇到的问题是,您必须在数组中添加一个新条目。我通过使用Arrays.copyof创建它的第二个版本,然后以增强的长度将它重新复制到原始版本来实现这一点。它似乎可以工作,通过控制台我可以打印我的新数组没有问题,完成新的条目。我遇到的问题是我的gui。。每次尝试在gui中显示新条目时,我都会 “线程“AWT-EventQue
ArrayList
我遇到的问题是,您必须在数组中添加一个新条目。我通过使用Arrays.copyof创建它的第二个版本,然后以增强的长度将它重新复制到原始版本来实现这一点。它似乎可以工作,通过控制台我可以打印我的新数组没有问题,完成新的条目。我遇到的问题是我的gui。。每次尝试在gui中显示新条目时,我都会
“线程“AWT-EventQueue-0”java.lang.ArrayIndexOutOfBoundsException中的异常:5”
我肯定我犯了一些愚蠢的错误,但是我已经度过了漫长的一天,我完全被这个问题难住了
package inventoryprogram3;
public class Inventoryprogram3 {
public static void main(String[] args) {
inventoryGui gui = new inventoryGui();
gui.setVisible(true);
}
}
package inventoryprogram3;
import java.io.Serializable;
class sItem implements Serializable{
int itemNumber;
String itemName;
int itemStock;
double itemPrice;
double stockTotal;
public sItem(int iNumber, String iName, int iStock, double iPrice){
itemNumber = iNumber;
itemName = iName;
itemStock = iStock;
itemPrice = iPrice;
}
}
public class rBook extends sItem {
int pCount;
double rFee;
public rBook(int iNumber, String iName, int iStock, double iPrice, int pageCount) {
super(iNumber, iName, iStock, iPrice);
pCount = pageCount;
rFee = (iPrice * iStock) * 1.05;
}
}
package inventoryprogram3;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
public class inventoryGui extends javax.swing.JFrame {
/**
* Creates new form inventoryGui
*/
static int max = 5;
static rBook[] rpg = new rBook[max];
double invValue;
int counter = -1;
public inventoryGui() {
initComponents();
rpg[0] = new rBook(1, "Mutants & Masterminds", 4, 19.99, 200);
rpg[1] = new rBook(2, "Exalted", 6, 25.99, 542);
rpg[2] = new rBook(3, "D&D Next", 15, 49.95, 350);
rpg[3] = new rBook(4, "Eclipse Phase", 3, 28.99, 426);
rpg[4] = new rBook(5, "The Mutant Epoch", 8, 19.99, 386);
}
private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
nameLabel = new javax.swing.JLabel();
titleLabel = new javax.swing.JLabel();
iNumberLabel = new javax.swing.JLabel();
priceLabel = new javax.swing.JLabel();
pCountlabel = new javax.swing.JLabel();
stockLabel = new javax.swing.JLabel();
restockLabel = new javax.swing.JLabel();
entireInventoryLabel = new javax.swing.JLabel();
restockField = new javax.swing.JTextField();
stockField = new javax.swing.JTextField();
pCountField = new javax.swing.JTextField();
priceField = new javax.swing.JTextField();
iNumberField = new javax.swing.JTextField();
titleField = new javax.swing.JTextField();
inventoryValueLabel = new javax.swing.JLabel();
inventoryValueField = new javax.swing.JTextField();
nextButton = new javax.swing.JButton();
entireInventoryField = new javax.swing.JTextField();
buttonLabel = new javax.swing.JLabel();
previousButton = new javax.swing.JButton();
companyLogo = new javax.swing.JLabel();
saveButton = new javax.swing.JButton();
loadButton = new javax.swing.JButton();
addbutton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
modifyButton = new javax.swing.JButton();
searchButton = new javax.swing.JButton();
jLabel4.setText("jLabel4");
jLabel2.setText("jLabel2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("RPG Inventory Program v0.4");
nameLabel.setText("Role Playing Game Inventory");
titleLabel.setText("Title");
iNumberLabel.setText("Item Number");
priceLabel.setText("Price");
pCountlabel.setText("Page Count");
stockLabel.setText("Copies in Stock");
restockLabel.setText("Restocking Fee");
entireInventoryLabel.setText("Value of Entire Inventory");
restockField.setEditable(false);
iNumberField.setEditable(false);
inventoryValueLabel.setText("Inventory Value");
nextButton.setText("Next");
nextButton.setToolTipText("Click toDisplay Next Item");
nextButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextButtonActionPerformed(evt);
}
});
entireInventoryField.setEditable(false);
buttonLabel.setText("Item Display");
previousButton.setText("Previous");
previousButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
previousButtonActionPerformed(evt);
}
});
companyLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/inventoryprogram3/logo4.png")));
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
loadButton.setText("Clear");
loadButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadButtonActionPerformed(evt);
}
});
addbutton.setText("Add");
addbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addbuttonActionPerformed(evt);
}
});
deleteButton.setText("Delete");
deleteButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteButtonActionPerformed(evt);
}
});
modifyButton.setText("Modify Current Item");
modifyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
modifyButtonActionPerformed(evt);
}
});
searchButton.setText("Search");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pCountlabel)
.addGap(18, 18, 18)
.addComponent(pCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(entireInventoryLabel))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(restockLabel)
.addGap(192, 192, 192)
.addComponent(previousButton))
.addGroup(layout.createSequentialGroup()
.addComponent(loadButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addbutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)
.addGap(18, 18, 18)
.addComponent(modifyButton)
.addGap(12, 12, 12)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(nextButton)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(saveButton))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(nameLabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(priceLabel)
.addGap(18, 18, 18)
.addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(titleLabel)
.addGap(18, 18, 18)
.addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(iNumberLabel)
.addGap(18, 18, 18)
.addComponent(iNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(searchButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(companyLogo)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(restockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(inventoryValueLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(inventoryValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(stockLabel)
.addGap(18, 18, 18)
.addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(entireInventoryField, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(buttonLabel)
.addGap(15, 15, 15)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {iNumberLabel, pCountlabel, priceLabel, restockLabel, stockLabel, titleLabel});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {iNumberField, inventoryValueField, pCountField, priceField, restockField, stockField, titleField});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(nameLabel)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(titleLabel)
.addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(searchButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(iNumberLabel)
.addComponent(iNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(priceLabel)
.addComponent(priceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(companyLogo, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pCountlabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(entireInventoryLabel)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(stockLabel)
.addComponent(stockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(entireInventoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(inventoryValueLabel)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(inventoryValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonLabel)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(restockLabel)
.addComponent(restockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(previousButton)
.addComponent(nextButton))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveButton)
.addComponent(addbutton)
.addComponent(deleteButton)
.addComponent(modifyButton)
.addComponent(loadButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(counter< max -1){
counter = counter + 1;
}
else{
counter = 0;
}
NumberFormat realMoney = NumberFormat.getCurrencyInstance(Locale.US);
invValue = 0;
for (int x=0; x < max -1; x++) {
invValue += rpg[x].itemStock * rpg[x].itemPrice;
}
System.out.println(counter);
titleField.setText(rpg[counter].itemName);
iNumberField.setText(String.valueOf(rpg[counter].itemNumber));
pCountField.setText(String.valueOf(rpg[counter].pCount));
priceField.setText(String.valueOf(realMoney.format(rpg[counter].itemPrice)));
stockField.setText(String.valueOf(rpg[counter].itemStock));
restockField.setText(String.valueOf(rpg[counter].rFee));
inventoryValueField.setText(String.valueOf(rpg[counter].itemStock * rpg[counter].itemPrice));
entireInventoryField.setText(String.valueOf(realMoney.format(invValue)));
}
private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(counter>= 1){
counter = counter - 1;
}
else{
counter = max -1;
}
NumberFormat realMoney = NumberFormat.getCurrencyInstance(Locale.US);
invValue = 0;
for (int x=0; x < max -1; x++) {
invValue += rpg[x].itemStock * rpg[x].itemPrice;
}
titleField.setText(rpg[counter].itemName);
iNumberField.setText(String.valueOf(rpg[counter].itemNumber));
pCountField.setText(String.valueOf(rpg[counter].pCount));
priceField.setText(String.valueOf(realMoney.format(rpg[counter].itemPrice)));
stockField.setText(String.valueOf(rpg[counter].itemStock));
restockField.setText(String.valueOf(rpg[counter].rFee));
inventoryValueField.setText(String.valueOf(rpg[counter].itemStock * rpg[counter].itemPrice));
entireInventoryField.setText(String.valueOf(realMoney.format(invValue)));
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
ObjectOutputStream savefile = null;
int dirmake = 1;
do{
try {
savefile = new ObjectOutputStream(new FileOutputStream("C:\\inventory\\inventory.dat"));
savefile.writeObject(rpg);
savefile.close();
dirmake = 2 ;
}
catch (Exception e){
String savePath = "c:\\Inventory";
Path invPath = Paths.get(savePath);
try {
Files.createDirectory(invPath);
} catch (IOException ex) {
Logger.getLogger(inventoryGui.class.getName()).log(Level.SEVERE, null, ex);
}
}
}while(dirmake == 1);
}
private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {
titleField.setText("");
iNumberField.setText("");
pCountField.setText("");
priceField.setText("");
stockField.setText("");
restockField.setText("");
inventoryValueField.setText("" );
entireInventoryField.setText("");
}
private void modifyButtonActionPerformed(java.awt.event.ActionEvent evt) {
int mINumber = Integer.parseInt(iNumberField.getText());
double ss = Double.parseDouble(priceField.getText().replaceAll("[^\\d.]", ""));
rpg[mINumber -1] = new rBook(mINumber, titleField.getText(), Integer.parseInt(stockField.getText()), ss, Integer.parseInt(pCountField.getText()));
}
private void addbuttonActionPerformed(java.awt.event.ActionEvent evt) {
double ss = Double.parseDouble(priceField.getText().replaceAll("[^\\d.]", ""));
max ++;
rBook[] rpg2 = Arrays.copyOf(rpg, rpg.length);
rBook[] rpg = Arrays.copyOf(rpg2, max);
rpg[max -1] = new rBook(max, titleField.getText(), Integer.parseInt(stockField.getText()), ss, Integer.parseInt(pCountField.getText()));
System.out.println(max + titleField.getText() + Integer.parseInt(stockField.getText()) + ss + Integer.parseInt(pCountField.getText()));
counter = -1;
System.out.println(max);
for (int x=0; x< max; x++) {
System.out.println("Item Number:" + rpg[5].itemNumber);
System.out.println("Rpg Name:" + rpg[5].itemName);
System.out.println("Copies in stock:" + rpg[5].itemStock);
System.out.println("Price: $" + (rpg[5].itemPrice));
System.out.println("Page Count:" + rpg[5].pCount);
System.out.println("Restocking fee: $" + (rpg[5].rFee));
System.out.println();
System.out.println();
System.out.println(rpg.length);
}
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(inventoryGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new inventoryGui().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addbutton;
private javax.swing.JLabel buttonLabel;
private javax.swing.JLabel companyLogo;
private javax.swing.JButton deleteButton;
private javax.swing.JTextField entireInventoryField;
private javax.swing.JLabel entireInventoryLabel;
private javax.swing.JTextField iNumberField;
private javax.swing.JLabel iNumberLabel;
private javax.swing.JTextField inventoryValueField;
private javax.swing.JLabel inventoryValueLabel;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JButton loadButton;
private javax.swing.JButton modifyButton;
private javax.swing.JLabel nameLabel;
private javax.swing.JButton nextButton;
private javax.swing.JTextField pCountField;
private javax.swing.JLabel pCountlabel;
private javax.swing.JButton previousButton;
private javax.swing.JTextField priceField;
private javax.swing.JLabel priceLabel;
private javax.swing.JTextField restockField;
private javax.swing.JLabel restockLabel;
private javax.swing.JButton saveButton;
private javax.swing.JButton searchButton;
private javax.swing.JTextField stockField;
private javax.swing.JLabel stockLabel;
private javax.swing.JTextField titleField;
private javax.swing.JLabel titleLabel;
}
package inventory程序3;
公共类目录程序3{
公共静态void main(字符串[]args){
inventoryGui=新的inventoryGui();
setVisible(true);
}
}
一揽子清单方案3;
导入java.io.Serializable;
类sItem实现可序列化{
整数项目编号;
字符串itemName;
国际商品库存;
双倍价格;
双倍库存总量;
公共站点(int-iNumber、字符串iName、int-iStock、双i价格){
itemNumber=iNumber;
itemName=iName;
itemStock=iStock;
itemPrice=iPrice;
}
}
公共类rBook扩展了sItem{
int pCount;
双rFee;
public-rBook(int-iNumber、字符串iName、int-iStock、double-iPrice、int-pageCount){
super(iNumber、iName、iStock、iPrice);
pCount=页面计数;
rFee=(iPrice*iStock)*1.05;
}
}
一揽子清单方案3;
导入java.io.*;
导入java.nio.file.Files;
导入java.nio.file.Path;
导入java.nio.file.path;
导入java.text.NumberFormat;
导入java.util.array;
导入java.util.Locale;
导入java.util.logging.Level;
导入java.util.logging.Logger;
公共类inventoryGui扩展了javax.swing.JFrame{
/**
*创建新表单inventoryGui
*/
静态int max=5;
静态rBook[]rpg=新rBook[max];
双重价值;
int计数器=-1;
公共目录GUI(){
初始化组件();
rpg[0]=新的rBook(1,“突变体和智囊团”,419.99200);
rpg[1]=新rBook(2,“崇高”,6,25.99542);
rpg[2]=新rBook(3,“下一步研发”,15,49.95350);
rpg[3]=新的rBook(4,“日食阶段”,328.99426);
rpg[4]=新的rBook(5,“突变时代”,819.99386);
}
私有组件(){
jLabel4=newjavax.swing.JLabel();
jLabel2=newjavax.swing.JLabel();
namelab=newjavax.swing.JLabel();
titleLabel=newjavax.swing.JLabel();
iNumberLabel=newjavax.swing.JLabel();
pricelab=newjavax.swing.JLabel();
pCountlabel=newjavax.swing.JLabel();
stockLabel=newjavax.swing.JLabel();
restockLabel=newjavax.swing.JLabel();
EntireventoryLabel=newjavax.swing.JLabel();
restockField=newjavax.swing.JTextField();
stockField=newjavax.swing.JTextField();
pCountField=newjavax.swing.JTextField();
priceField=newjavax.swing.JTextField();
iNumberField=newjavax.swing.JTextField();
titleField=newjavax.swing.JTextField();
inventoryValueLabel=newjavax.swing.JLabel();
inventoryValueField=newjavax.swing.JTextField();
nextButton=newjavax.swing.JButton();
EntireventoryField=newjavax.swing.JTextField();
buttonLabel=newjavax.swing.JLabel();
previousButton=newjavax.swing.JButton();
companyLogo=newjavax.swing.JLabel();
saveButton=newjavax.swing.JButton();
loadButton=newjavax.swing.JButton();
addbutton=newjavax.swing.JButton();
deleteButton=newjavax.swing.JButton();
modifyButton=newjavax.swing.JButton();
searchButton=newjavax.swing.JButton();
jLabel4.setText(“jLabel4”);
jLabel2.setText(“jLabel2”);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“RPG库存计划v0.4”);
namelab.setText(“角色扮演游戏目录”);
titleLabel.setText(“标题”);
iNumberLabel.setText(“项目编号”);
pricelab.setText(“价格”);
pCountlabel.setText(“页数”);
stockLabel.setText(“库存副本”);
重新进货标签.setText(“重新进货费用”);
entireInventoryLabel.setText(“整个存货的价值”);
重新进货字段。设置可编辑(false);
iNumberField.setEditable(false);
inventoryValueLabel.setText(“库存值”);
setText(“下一步”);
setToolTipText(“单击以显示下一项”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行下一个按钮操作(evt);
}
});
EntireventoryField.setEditable(false);
buttonLabel.setText(“项目显示”);
previousButton.setText(“上一个”);
previousButton.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
先前执行的按钮操作(evt);
}
});
setIcon(新的javax.swing.ImageIcon(getClass().getResource(“/inventoryprogram3/logo4.png”));
saveButton.setText(“保存”);
saveButton.addActionListener(新java.awt.event.ActionListener(){
已执行的公共无效诉讼
max ++;
rBook[] rpg2 = Arrays.copyOf(rpg, rpg.length);
rBook[] rpg = Arrays.copyOf(rpg2, max);
rpg = Arrays.copyOf(rpg2, max);
rBook[] rpg2 = new rBook[rpg.length + 1];
System.arraycopy(rpg, 0, rpg2, 0, rpg.length - 1);
rpg = rpg2;