Hej med jer.. Jeg har en opgave jeg skal aflevere på onsdag. puha hehe. Jeg har en lille fejl som jeg ikke lige kan gennemskue, så jeg håbede der var nogen her inde der gad hjælpe mig.
Når jeg indtaster nogle data som så gemmes i en fil også lukker programmet og åbner det igen og arraylisten loades. Så kan jeg ikke rette i arraylisten, slette i den. Ikke før jeg opretter en ny ting i array'en. Så kan jeg slette alt også den der var gemt fra tidligere.
Jeg får følgende fejl når jeg prøver at slette eller rette i et gemt array: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Co2BeregnerJFrame.java
*
* Created on 20-05-2009, 20:10:39
*/
package javaapplicationco2beregner;
import java.util.ArrayList;
import java.io.*;
/**
*
* @author Thomas
*/
public class Co2BeregnerJFrame extends javax.swing.JFrame {
public ArrayList al = new ArrayList();
boolean kontrol = true;
/** Creates new form Co2BeregnerJFrame */
public Co2BeregnerJFrame() {
initComponents();
try {
Load();
jList1.setListData( al.toArray() );
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void Save() {
try {
FileOutputStream fileOutput = new FileOutputStream("datah.dat");
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
objectOutput.writeObject(al);
objectOutput.close();
}
catch(Exception e) {
System.out.println("Save error");
}
}
public void Load()
{
try {
FileInputStream fileInput = new FileInputStream("datah.dat");
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
al = (ArrayList)objectInput.readObject();
objectInput.close();
}
catch( Exception e ) {
e.printStackTrace();
System.out.println("Load error");
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel15 = new javax.swing.JLabel();
jTextField11 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
jSeparator4 = new javax.swing.JSeparator();
jLabel14 = new javax.swing.JLabel();
jTextField12 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jSeparator2 = new javax.swing.JSeparator();
jSeparator5 = new javax.swing.JSeparator();
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jLabel16 = new javax.swing.JLabel();
jTextField13 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setText("Angiv Deres lands forbrug af strøm angivet i MW over 1 år:");
jLabel3.setText("Angiv antal kræftværker:");
jLabel4.setText("Angiv gennemsnit af afstanden til nærmeste by i kilometer:");
jLabel5.setText("Angiv antal vindmøller:");
jLabel8.setText("Blæsetimer pr. år med 100 % udnyttelse: ");
jLabel9.setText("Angiv værkets / værkernes ydelse i %:");
jLabel10.setText("Angiv antal kvadratmeter for solcellekræftværk:");
jLabel11.setText("Angiv om værket er styrbar:");
jLabel12.setText("Solskinstimer for området med 100% udnyttelse:");
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 36));
jLabel13.setText("BEREGN CO2 - COP15");
jTextField2.setColumns(10);
jTextField2.setText("90000000");
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
jTextField3.setColumns(10);
jTextField4.setColumns(10);
jTextField5.setColumns(10);
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jTextField6.setColumns(10);
jLabel6.setText("Vindmøllerne er:");
jTextField7.setColumns(10);
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField7ActionPerformed(evt);
}
});
jTextField8.setColumns(10);
jTextField8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField8ActionPerformed(evt);
}
});
jTextField9.setColumns(10);
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel15.setText("Samlede mængde Co2 produceret angivet i tons:");
jTextField11.setColumns(10);
jTextField11.setEditable(false);
jTextField11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField11ActionPerformed(evt);
}
});
jButton2.setText("Ret");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Slet");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel14.setText("Status:");
jTextField12.setColumns(10);
jTextField12.setEditable(false);
jTextField12.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jTextField12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField12ActionPerformed(evt);
}
});
jButton4.setText("Gem");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("Gem");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("Gem");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "On shore", "Off shore" }));
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ja", "Nej" }));
jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel16.setText("MW mangler at blive produceret:");
jTextField13.setColumns(10);
jTextField13.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 1188, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(61, 61, 61)
.addComponent(jLabel14)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(606, Short.MAX_VALUE))
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 1188, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel13)
.addGap(44, 44, 44)
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(58, 58, 58)
.addComponent(jLabel16)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(40, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField7, javax.swing.GroupLayout.Alignment.LEADING)))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel8)
.addComponent(jLabel6))
.addGap(74, 74, 74)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jButton5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jLabel12))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jButton6))
.addContainerGap(49, Short.MAX_VALUE))
.addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 1188, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(437, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel13))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel15)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel16)
.addComponent(jTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14)
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(jTextField6, 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.BASELINE)
.addComponent(jLabel8)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(jTextField9, 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.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9)
.addComponent(jLabel11)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField3, 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.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6)))
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code her
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
Kraftvaerk k1 = new Kraftvaerk( Integer.parseInt( jTextField3.getText() ), Integer.parseInt( jTextField5.getText() ), Integer.parseInt( jTextField7.getText() ),10000000,100000,40000,100,25, Integer.parseInt( jTextField2.getText() ) );
if( kontrol ) {
k1.setSamletMW( k1.getAntalkraftvaerker() * k1.getMegawatt() * k1.getYdelse() / 100);
k1.setSamletco2( k1.getAfstandtilby() * k1.getVarmeudledning() * k1.getAntalkraftvaerker() * k1.getYdelse() / 100 );
jTextField13.setText( Integer.parseInt( jTextField2.getText() ) - k1.getSamletMW() + "" );
jTextField11.setText( k1.getSamletco2() + "" );
kontrol = false;
}
else
{
k1.setSamletMW( k1.getAntalkraftvaerker() * k1.getMegawatt() * k1.getYdelse() / 100 );
k1.setSamletco2( k1.getAfstandtilby() * k1.getVarmeudledning() * k1.getAntalkraftvaerker() * k1.getYdelse() / 100 );
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) - k1.getSamletMW() + "" );
jTextField11.setText( Integer.parseInt( jTextField11.getText() ) + k1.getSamletco2() + "" );
}
al.add( k1 );
jList1.setListData( al.toArray() );
try {
Serialisering.gem( al, "datah.dat" );
} catch (IOException ex) {
ex.printStackTrace();
}
Save();
jTextField12.setText( "Kraftværk gemt..." );
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Object Energikilder = jList1.getSelectedValue();
if ( Energikilder instanceof Kraftvaerk ) {
Kraftvaerk Kraftvaerk = ( Kraftvaerk ) Energikilder;
int MWold = Kraftvaerk.getSamletMW();
int CO2old = Kraftvaerk.getSamletco2();
Kraftvaerk.setAntalkraftvaerker( Integer.parseInt( jTextField3.getText() ) );
Kraftvaerk.setAfstandtilby( Integer.parseInt( jTextField5.getText() ) );
Kraftvaerk.setYdelse( Integer.parseInt( jTextField7.getText() ) );
Kraftvaerk.setSamletMW( Kraftvaerk.getAntalkraftvaerker() * Kraftvaerk.getMegawatt() * Kraftvaerk.getYdelse() / 100 );
Kraftvaerk.setSamletco2( Kraftvaerk.getAfstandtilby() * Kraftvaerk.getVarmeudledning() * Kraftvaerk.getAntalkraftvaerker() * Kraftvaerk.getYdelse() / 100 );
if ( MWold > Kraftvaerk.getSamletMW() ){
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) + MWold - Kraftvaerk.getSamletMW() + "" );
jTextField11.setText( Integer.parseInt( jTextField11.getText() ) - CO2old + Kraftvaerk.getSamletco2() + "" );
}
else {
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) + MWold - Kraftvaerk.getSamletMW() + "" );
jTextField11.setText( Integer.parseInt( jTextField11.getText() ) - CO2old + Kraftvaerk.getSamletco2() + "" );
}
}
if ( Energikilder instanceof Vindmoeller ) {
Vindmoeller Vindmoeller = ( Vindmoeller ) Energikilder;
int MWold = Vindmoeller.getSamletMW();
Vindmoeller.setAntalvindmoeller( Integer.parseInt( jTextField4.getText() ) );
Vindmoeller.setVindydelse( Integer.parseInt( jTextField8.getText() ) );
Vindmoeller.setSamletMW( Vindmoeller.getAntalvindmoeller() * Vindmoeller.getVindydelse() * Vindmoeller.getMegawatt() / 100 );
if ( MWold > Vindmoeller.getSamletMW() ){
jTextField13.setText(Integer.parseInt( jTextField13.getText() ) + MWold - Vindmoeller.getSamletMW() +"" );
}
else {
jTextField13.setText(Integer.parseInt( jTextField13.getText() ) + MWold - Vindmoeller.getSamletMW() +"" );
}
}
if ( Energikilder instanceof Solcellevaerk ) {
Solcellevaerk Solcellevaerk = ( Solcellevaerk ) Energikilder;
int MWold = Solcellevaerk.getSamletMW();
Solcellevaerk.setKvadratmeter( Integer.parseInt( jTextField6.getText() ) );
Solcellevaerk.setSolydelse( Integer.parseInt( jTextField9.getText() ) );
Solcellevaerk.setSamletMW( Solcellevaerk.getKvadratmeter() * Solcellevaerk.getSolydelse() * Solcellevaerk.getMegawatt() );
if ( MWold > Solcellevaerk.getSamletMW() ){
jTextField13.setText(Integer.parseInt( jTextField13.getText() ) + MWold - Solcellevaerk.getSamletMW() + "" );
}
else {
jTextField13.setText(Integer.parseInt( jTextField13.getText() ) + MWold - Solcellevaerk.getSamletMW() + "" );
}
}
jList1.setListData( al.toArray() );
Save();
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
Vindmoeller v1 = new Vindmoeller( Integer.parseInt( jTextField4.getText() ), Integer.parseInt( jTextField8.getText() ),0,0,0,0,0,10, Integer.parseInt( jTextField2.getText() ) );
switch( jComboBox1.getSelectedIndex() )
{
case 0:
v1.setMegawatt( 65000 );
v1.setCo2vedproduktion( 45 );
break;
case 1:
v1.setMegawatt( 100000 );
v1.setCo2vedproduktion( 55 );
break;
}
if( kontrol ) {
v1.setSamletMW( v1.getAntalvindmoeller() * v1.getMegawatt() * v1.getVindydelse() / 100 );
v1.setSamletco2(v1.getAntalvindmoeller() * v1.getCo2vedproduktion() );
jTextField13.setText( Integer.parseInt( jTextField2.getText() ) - v1.getSamletMW() + "" );
jTextField11.setText( v1.getSamletco2() + "" );
kontrol = false;
}
else{
v1.setSamletMW( v1.getAntalvindmoeller() * v1.getMegawatt() * v1.getVindydelse() / 100 );
v1.setSamletco2( v1.getAntalvindmoeller() * v1.getCo2vedproduktion() );
jTextField11.setText( v1.getSamletco2() + Integer.parseInt( jTextField11.getText() ) + "" );
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) - v1.getSamletMW() + "" );
jTextField3.setText(v1.getSamletMW() + "");
}
al.add( v1 );
jList1.setListData( al.toArray() );
Save();
jTextField12.setText( "Vindmølleværk gemt..." );
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
Solcellevaerk s1 = new Solcellevaerk(Integer.parseInt( jTextField6.getText() ), Integer.parseInt( jTextField9.getText() ),0,1,0,0,10,100, Integer.parseInt( jTextField2.getText() ) );
switch( jComboBox2.getSelectedIndex() )
{
case 0:
s1.setStyrbar( 100 );
break;
case 1:
s1.setStyrbar( 35 );
break;
}
if( kontrol ) {
s1.setSamletMW( s1.getKvadratmeter() * s1.getSolydelse() * s1.getStyrbar() );
s1.setSamletco2( s1.getKvadratmeter() * s1.getCo2vedproduktion() );
jTextField13.setText( Integer.parseInt( jTextField2.getText() ) - s1.getSamletMW() + "" );
jTextField11.setText( s1.getSamletco2() + "" );
kontrol = false;
}
else{
s1.setSamletMW( s1.getKvadratmeter() * s1.getSolydelse() );
s1.setSamletco2( s1.getKvadratmeter() * s1.getCo2vedproduktion() );
jTextField11.setText( s1.getSamletco2() + Integer.parseInt( jTextField11.getText() ) + "" );
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) - s1.getSamletMW() + "" );
}
al.add( s1 );
jList1.setListData( al.toArray() );
Save();
jTextField12.setText( "Solcelle/Værk gemt!" );
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
Energikilder o1 = ( Energikilder )jList1.getSelectedValue();
if( o1 instanceof Kraftvaerk ){
jTextField11.setText( Integer.parseInt( jTextField11.getText() ) - o1.getSamletco2() + "" );
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) + o1.getSamletMW() + "" );
jTextField12.setText( "Kraftværk slettet..." );
}
if( o1 instanceof Vindmoeller ){
jTextField11.setText( Integer.parseInt(jTextField11.getText() ) - o1.getSamletco2() + "" );
jTextField13.setText( Integer.parseInt(jTextField13.getText() ) + o1.getSamletMW() + "" );
jTextField12.setText( "Vindmølleværk slettet..." );
}
if( o1 instanceof Solcellevaerk ){
jTextField11.setText( Integer.parseInt( jTextField11.getText() ) - o1.getSamletco2() + "" );
jTextField13.setText( Integer.parseInt( jTextField13.getText() ) + o1.getSamletMW() + "" );
jTextField12.setText( "Solcelleværk slettet..." );
}
al.remove( jList1.getSelectedIndex() ); jList1.setListData( al.toArray() );
Save();
}
private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Co2BeregnerJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JSeparator jSeparator4;
private javax.swing.JSeparator jSeparator5;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField13;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
// End of variables declaration
}