Results 1 to 20 of 20

Thread: exspected!!

  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default exspected!!

    private void BerekenloneMouseClicked(MouseEvent e) {
    kalkuleerlone vlgobj = new kalkuleerlone(tot1));
    }

    and this is the message it gives me:

    Lone.java:43: ';' expected
    kalkuleerlone vlgobj = new kalkuleerlone(tot1));
    ^


    please help its driving me crazy!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Thanx but that still doesnt fix my error...:(

  4. #4
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    You've got an extra closing bracket (parenthesis) after tot1.
    Java Code:
    kalkuleerlone vlgobj = new kalkuleerlone(tot1[U])[/U];
    If you *have* removed that, then please could you repost your new code and the error.

  5. #5
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Thanx!! I solved the problem...tot1 was in another method...OEPS...but maby you can help me put a do while loop in this program...? Don't wory about the unfinished parts. What I want is when you press the OK button thats called "verlaat" it must ask with a JOptionPane MessageDialog if you want to continue with the program...if you answer y the program must run again, but if you answer no the program must end...PLEASE HELP me, I sat the whole if today with the problem. I would be so grateful if any body could put this loop in for me!!!!:( Here is the whole program:


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;

    /*
    * Created by JFormDesigner on Sat Oct 30 11:47:07 CAT 2010
    */



    /**
    * @author JJ Minnie
    */
    public class Lone extends JFrame
    {

    public Lone()
    {
    this.setVisible(true);
    }

    public static void main(String[]args)
    {
    Lone obj1 = new Lone();
    }
    private void BerekentotMouseClicked(MouseEvent e)
    {//totaal1
    double Loonperdag1 = Double.parseDouble(Dagloon.getText());
    double ae1 = Double.parseDouble(dae1.getText());
    double y1 = Double.parseDouble(by1.getText());
    double f1 = Double.parseDouble(af1.getText());
    double btot1 = Loonperdag1*ae1+y1-f1;
    double een = btot1 * 100;
    double een1 = Math.round(een);
    double een2 = een1 / 100;
    String ot1 = "" + een2;
    tot1.setText(ot1);
    //totaal2
    double Loonperdag2 = Double.parseDouble(Dagloon.getText());
    double ae2 = Double.parseDouble(dae2.getText());
    double y2 = Double.parseDouble(by2.getText());
    double f2 = Double.parseDouble(af2.getText());
    double btot2 = Loonperdag2*ae2+y2-f2;
    double twee = btot2 * 100;
    double twee1 = Math.round(twee);
    double twee2 = twee1 / 100;
    String ot2 = "" + twee2;
    tot2.setText(ot2);
    //totaal3
    double Loonperdag3 = Double.parseDouble(Dagloon.getText());
    double ae3 = Double.parseDouble(dae3.getText());
    double y3 = Double.parseDouble(by3.getText());
    double f3 = Double.parseDouble(af3.getText());
    double btot3 = Loonperdag3*ae3+y3-f3;
    double drie = btot3 * 100;
    double drie1 = Math.round(drie);
    double drie2 = drie1 / 100;
    String ot3 = "" + drie2;
    tot3.setText(ot3);
    //totaal4
    double Loonperdag4 = Double.parseDouble(Dagloon.getText());
    double ae4 = Double.parseDouble(dae4.getText());
    double y4 = Double.parseDouble(by4.getText());
    double f4 = Double.parseDouble(af4.getText());
    double btot4 = Loonperdag4*ae4+y4-f4;
    double vier = btot4 * 100;
    double vier1 = Math.round(vier);
    double vier2 = vier1 / 100;
    String ot4 = "" + vier2;
    tot4.setText(ot4);
    //totaal5
    double Loonperdag5 = Double.parseDouble(Dagloon.getText());
    double ae5 = Double.parseDouble(dae5.getText());
    double y5 = Double.parseDouble(by5.getText());
    double f5 = Double.parseDouble(af5.getText());
    double btot5 = Loonperdag5*ae5+y5-f5;
    double vyf = btot5 * 100;
    double vyf1 = Math.round(vyf);
    double vyf2 = vyf1 / 100;
    String ot5 = "" + vyf2;
    tot5.setText(ot5);
    //totaal6
    double Loonperdag6 = Double.parseDouble(Dagloon.getText());
    double ae6 = Double.parseDouble(dae6.getText());
    double y6 = Double.parseDouble(by6.getText());
    double f6 = Double.parseDouble(af6.getText());
    double btot6 = Loonperdag6*ae6+y6-f6;
    double ses = btot6 * 100;
    double ses1 = Math.round(ses);
    double ses2 = ses1 / 100;
    String ot6 = "" + ses2;
    tot6.setText(ot6);
    //totaal7
    double Loonperdag7 = Double.parseDouble(Dagloon.getText());
    double ae7 = Double.parseDouble(dae7.getText());
    double y7 = Double.parseDouble(by7.getText());
    double f7 = Double.parseDouble(af7.getText());
    double btot7 = Loonperdag7*ae7+y7-f7;
    double sewe = btot7 * 100;
    double sewe1 = Math.round(sewe);
    double sewe2 = sewe1 / 100;
    String ot7 = "" + sewe2;
    tot7.setText(ot7);
    //totaal8
    double Loonperdag8 = Double.parseDouble(Dagloon.getText());
    double ae8 = Double.parseDouble(dae8.getText());
    double y8 = Double.parseDouble(by8.getText());
    double f8 = Double.parseDouble(af8.getText());
    double btot8 = Loonperdag8*ae8+y8-f8;
    double agt = btot8 * 100;
    double agt1 = Math.round(agt);
    double agt2 = agt1 / 100;
    String ot8 = "" + agt2;
    tot8.setText(ot8);
    //totaal9
    double Loonperdag9 = Double.parseDouble(Dagloon.getText());
    double ae9 = Double.parseDouble(dae9.getText());
    double y9 = Double.parseDouble(by9.getText());
    double f9 = Double.parseDouble(af9.getText());
    double btot9 = Loonperdag3*ae9+y9-f9;
    double nege = btot9 * 100;
    double nege1 = Math.round(nege);
    double nege2 = nege1 / 100;
    String ot9 = "" + nege2;
    tot9.setText(ot9);
    //Totaal10
    double Loonperdag10 = Double.parseDouble(Dagloon.getText());
    double ae10 = Double.parseDouble(dae10.getText());
    double y10 = Double.parseDouble(by10.getText());
    double f10 = Double.parseDouble(af10.getText());
    double btot10 = Loonperdag3*ae10+y10-f10;
    double tien = btot10 * 100;
    double tien1 = Math.round(tien);
    double tien2 = tien1 / 100;
    String ot10 = "" + tien2;
    tot10.setText(ot10);
    }

    private void BerekenloneMouseClicked(MouseEvent e)
    {
    kalkuleerlone obj = new kalkuleerlone(300);
    double probeer = obj.getHonderd();
    }

    private void VeldskoonMouseClicked(MouseEvent e) {
    naam1.setText("");
    naam2.setText("");
    naam3.setText("");
    naam4.setText("");
    naam5.setText("");
    naam6.setText("");
    naam7.setText("");
    naam8.setText("");
    naam9.setText("");
    naam10.setText("");
    dae1.setText("");
    dae2.setText("");
    dae3.setText("");
    dae4.setText("");
    dae5.setText("");
    dae6.setText("");
    dae7.setText("");
    dae8.setText("");
    dae9.setText("");
    dae10.setText("");
    by1.setText("");
    by2.setText("");
    by4.setText("");
    by3.setText("");
    by5.setText("");
    by6.setText("");
    by7.setText("");
    by8.setText("");
    by9.setText("");
    by10.setText("");
    af1.setText("");
    af2.setText("");
    af3.setText("");
    af4.setText("");
    af5.setText("");
    af6.setText("");
    af7.setText("");
    af8.setText("");
    af9.setText("");
    af10.setText("");
    tot1.setText("");
    tot2.setText("");
    tot3.setText("");
    tot4.setText("");
    tot5.setText("");
    tot6.setText("");
    tot7.setText("");
    tot8.setText("");
    tot9.setText("");
    tot10.setText("");
    Dag.setText("");
    Maand.setText("");
    Jaar.setText("");
    Dagloon.setText("");
    }

    public void okButtonMouseClicked(MouseEvent e)
    {

    }

    private void helpButtonMouseClicked(MouseEvent e) {
    JOptionPane.showMessageDialog(null,"");
    }

    private void AfrikaansMouseClicked(MouseEvent e) {
    Ldatum.setText("Datum:");
    Ljaar.setText("JJJJ");
    Ldagloon.setText("Loon per dag:");
    Lnaam.setText("Naam en van");
    Laantaldae.setText("Aantal dae");
    Lgewerk.setText("gewerk");
    Lbyvoegings.setText("Byvoegings");
    Ltotaal.setText("Totaal");
    Veldskoon.setText("Wis velde uit");
    Berekenlone.setText("Bereken lone");
    okButton.setText("Verlaat");
    helpButton.setText("Hulp");
    Laftrekkings.setText("Aftrekkings");
    Ldagloon.setText("Loon per dag: R");
    }

    private void EngelsMouseClicked(MouseEvent e) {
    Ldatum.setText(" Date:");
    Ljaar.setText("YYYY");
    Ldagloon.setText("Wage per day");
    Lnaam.setText("Name and surname");
    Laantaldae.setText(" Days");
    Lgewerk.setText("worked");
    Lbyvoegings.setText("Additions");
    Ltotaal.setText("Total");
    Veldskoon.setText("Clear fields");
    Berekenlone.setText("Calculate wages");
    okButton.setText("Exit");
    helpButton.setText("Help");
    Laftrekkings.setText("Deductions");
    Ldagloon.setText("Wage per day R");
    }

    private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    Ldatum = new JLabel();
    Dag = new JTextField();
    Maand = new JTextField();
    Jaar = new JTextField();
    Ldag = new JLabel();
    Lmaand = new JLabel();
    Ljaar = new JLabel();
    Ldagloon = new JLabel();
    Dagloon = new JTextField();
    Lnaam = new JLabel();
    Laantaldae = new JLabel();
    Lbyvoegings = new JLabel();
    Laftrekkings = new JLabel();
    Lgewerk = new JLabel();
    naam1 = new JTextField();
    naam2 = new JTextField();
    naam3 = new JTextField();
    naam4 = new JTextField();
    naam5 = new JTextField();
    naam6 = new JTextField();
    naam7 = new JTextField();
    naam8 = new JTextField();
    naam9 = new JTextField();
    naam10 = new JTextField();
    dae1 = new JTextField();
    dae2 = new JTextField();
    dae3 = new JTextField();
    dae4 = new JTextField();
    dae5 = new JTextField();
    dae6 = new JTextField();
    dae7 = new JTextField();
    dae8 = new JTextField();
    dae9 = new JTextField();
    dae10 = new JTextField();
    by1 = new JTextField();
    by2 = new JTextField();
    by3 = new JTextField();
    by4 = new JTextField();
    by5 = new JTextField();
    by6 = new JTextField();
    by7 = new JTextField();
    by8 = new JTextField();
    by9 = new JTextField();
    by10 = new JTextField();
    af1 = new JTextField();
    af2 = new JTextField();
    af3 = new JTextField();
    af4 = new JTextField();
    af5 = new JTextField();
    af6 = new JTextField();
    af7 = new JTextField();
    af8 = new JTextField();
    af9 = new JTextField();
    af10 = new JTextField();
    Ltotaal = new JLabel();
    tot1 = new JTextField();
    tot2 = new JTextField();
    tot3 = new JTextField();
    tot4 = new JTextField();
    tot5 = new JTextField();
    tot6 = new JTextField();
    tot7 = new JTextField();
    tot8 = new JTextField();
    tot9 = new JTextField();
    tot10 = new JTextField();
    Berekentot = new JButton();
    Berekenlone = new JButton();
    Veldskoon = new JButton();
    separator2 = new JSeparator();
    okButton = new JButton();
    helpButton = new JButton();
    Afrikaans = new JButton();
    Engels = new JButton();
    label15 = new JLabel();

    //======== this ========
    setTitle("Inligting invoering");
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== dialogPane ========
    {
    dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    dialogPane.setLayout(new BorderLayout());

    //======== contentPanel ========
    {
    contentPanel.setLayout(null);

    //---- Ldatum ----
    Ldatum.setText("Datum:");
    contentPanel.add(Ldatum);
    Ldatum.setBounds(105, 5, Ldatum.getPreferredSize().width, 19);
    contentPanel.add(Dag);
    Dag.setBounds(145, 5, 40, Dag.getPreferredSize().height);
    contentPanel.add(Maand);
    Maand.setBounds(195, 5, 40, Maand.getPreferredSize().height);
    contentPanel.add(Jaar);
    Jaar.setBounds(245, 5, 40, Jaar.getPreferredSize().height);

    //---- Ldag ----
    Ldag.setText(" DD");
    contentPanel.add(Ldag);
    Ldag.setBounds(new Rectangle(new Point(155, 25), Ldag.getPreferredSize()));

    //---- Lmaand ----
    Lmaand.setText(" MM");
    contentPanel.add(Lmaand);
    Lmaand.setBounds(new Rectangle(new Point(205, 25), Lmaand.getPreferredSize()));

    //---- Ljaar ----
    Ljaar.setText("JJJJ");
    contentPanel.add(Ljaar);
    Ljaar.setBounds(new Rectangle(new Point(255, 25), Ljaar.getPreferredSize()));

    //---- Ldagloon ----
    Ldagloon.setText("Loon per dag: R");
    contentPanel.add(Ldagloon);
    Ldagloon.setBounds(5, 35, Ldagloon.getPreferredSize().width, 19);
    contentPanel.add(Dagloon);
    Dagloon.setBounds(95, 35, 60, Dagloon.getPreferredSize().height);

    //---- Lnaam ----
    Lnaam.setText("Naam en van");
    contentPanel.add(Lnaam);
    Lnaam.setBounds(20, 75, 120, Lnaam.getPreferredSize().height);

    //---- Laantaldae ----
    Laantaldae.setText("Aantal dae");
    contentPanel.add(Laantaldae);
    Laantaldae.setBounds(new Rectangle(new Point(150, 65), Laantaldae.getPreferredSize()));

    //---- Lbyvoegings ----
    Lbyvoegings.setText("Byvoegings");
    contentPanel.add(Lbyvoegings);
    Lbyvoegings.setBounds(new Rectangle(new Point(215, 75), Lbyvoegings.getPreferredSize()));

    //---- Laftrekkings ----
    Laftrekkings.setText("Aftrekkings");
    contentPanel.add(Laftrekkings);
    Laftrekkings.setBounds(new Rectangle(new Point(285, 75), Laftrekkings.getPreferredSize()));

    //---- Lgewerk ----
    Lgewerk.setText("gewerk");
    contentPanel.add(Lgewerk);
    Lgewerk.setBounds(160, 75, 50, Lgewerk.getPreferredSize().height);
    contentPanel.add(naam1);
    naam1.setBounds(15, 95, 125, 20);
    contentPanel.add(naam2);
    naam2.setBounds(15, 120, 125, 20);
    contentPanel.add(naam3);
    naam3.setBounds(15, 145, 125, 20);
    contentPanel.add(naam4);
    naam4.setBounds(15, 170, 125, 20);
    contentPanel.add(naam5);
    naam5.setBounds(15, 195, 125, 20);
    contentPanel.add(naam6);
    naam6.setBounds(15, 220, 125, 20);
    contentPanel.add(naam7);
    naam7.setBounds(15, 245, 125, 20);
    contentPanel.add(naam8);
    naam8.setBounds(15, 270, 125, 20);
    contentPanel.add(naam9);
    naam9.setBounds(15, 295, 125, 20);
    contentPanel.add(naam10);
    naam10.setBounds(15, 320, 125, 20);
    contentPanel.add(dae1);
    dae1.setBounds(155, 95, 50, dae1.getPreferredSize().height);
    contentPanel.add(dae2);
    dae2.setBounds(155, 120, 50, 20);
    contentPanel.add(dae3);
    dae3.setBounds(155, 145, 50, 20);
    contentPanel.add(dae4);
    dae4.setBounds(155, 170, 50, 20);
    contentPanel.add(dae5);
    dae5.setBounds(155, 195, 50, 20);
    contentPanel.add(dae6);
    dae6.setBounds(155, 220, 50, 20);
    contentPanel.add(dae7);
    dae7.setBounds(155, 245, 50, 20);
    contentPanel.add(dae8);
    dae8.setBounds(155, 270, 50, 20);
    contentPanel.add(dae9);
    dae9.setBounds(155, 295, 50, 20);
    contentPanel.add(dae10);
    dae10.setBounds(155, 320, 50, 20);
    contentPanel.add(by1);
    by1.setBounds(220, 95, 50, 20);
    contentPanel.add(by2);
    by2.setBounds(220, 120, 50, 20);
    contentPanel.add(by3);
    by3.setBounds(220, 145, 50, 20);
    contentPanel.add(by4);
    by4.setBounds(220, 170, 50, 20);
    contentPanel.add(by5);
    by5.setBounds(220, 195, 50, 20);
    contentPanel.add(by6);
    by6.setBounds(220, 220, 50, 20);
    contentPanel.add(by7);
    by7.setBounds(220, 245, 50, 20);
    contentPanel.add(by8);
    by8.setBounds(220, 270, 50, 20);
    contentPanel.add(by9);
    by9.setBounds(220, 295, 50, 20);
    contentPanel.add(by10);
    by10.setBounds(220, 320, 50, 20);
    contentPanel.add(af1);
    af1.setBounds(285, 95, 50, 20);
    contentPanel.add(af2);
    af2.setBounds(285, 120, 50, 20);
    contentPanel.add(af3);
    af3.setBounds(285, 145, 50, 20);
    contentPanel.add(af4);
    af4.setBounds(285, 170, 50, 20);
    contentPanel.add(af5);
    af5.setBounds(285, 195, 50, 20);
    contentPanel.add(af6);
    af6.setBounds(285, 220, 50, 20);
    contentPanel.add(af7);
    af7.setBounds(285, 245, 50, 20);
    contentPanel.add(af8);
    af8.setBounds(285, 270, 50, 20);
    contentPanel.add(af9);
    af9.setBounds(285, 295, 50, 20);
    contentPanel.add(af10);
    af10.setBounds(285, 320, 50, 20);

    //---- Ltotaal ----
    Ltotaal.setText("Totaal");
    contentPanel.add(Ltotaal);
    Ltotaal.setBounds(new Rectangle(new Point(355, 75), Ltotaal.getPreferredSize()));
    contentPanel.add(tot1);
    tot1.setBounds(350, 95, 50, 20);
    contentPanel.add(tot2);
    tot2.setBounds(350, 120, 50, 20);
    contentPanel.add(tot3);
    tot3.setBounds(350, 145, 50, 20);
    contentPanel.add(tot4);
    tot4.setBounds(350, 170, 50, 20);
    contentPanel.add(tot5);
    tot5.setBounds(350, 195, 50, 20);
    contentPanel.add(tot6);
    tot6.setBounds(350, 220, 50, 20);
    contentPanel.add(tot7);
    tot7.setBounds(350, 245, 50, 20);
    contentPanel.add(tot8);
    tot8.setBounds(350, 270, 50, 20);
    contentPanel.add(tot9);
    tot9.setBounds(350, 295, 50, 20);
    contentPanel.add(tot10);
    tot10.setBounds(350, 320, 50, 20);

    //---- Berekentot ----
    Berekentot.setText("Bereken totaal");
    Berekentot.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    BerekentotMouseClicked(e);
    }
    });
    contentPanel.add(Berekentot);
    Berekentot.setBounds(275, 345, 125, Berekentot.getPreferredSize().height);

    //---- Berekenlone ----
    Berekenlone.setText("Bereken lone");
    Berekenlone.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    BerekenloneMouseClicked(e);
    }
    });
    contentPanel.add(Berekenlone);
    Berekenlone.setBounds(85, 380, 243, 38);

    //---- Veldskoon ----
    Veldskoon.setText("Wis velde uit");
    Veldskoon.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    VeldskoonMouseClicked(e);
    }
    });
    contentPanel.add(Veldskoon);
    Veldskoon.setBounds(15, 345, 130, Veldskoon.getPreferredSize().height);
    contentPanel.add(separator2);
    separator2.setBounds(0, 60, 415, 5);

    //---- okButton ----
    okButton.setText("Verlaat");
    okButton.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    okButtonMouseClicked(e);
    }
    });
    contentPanel.add(okButton);
    okButton.setBounds(245, 440, 80, okButton.getPreferredSize().height);

    //---- helpButton ----
    helpButton.setText("Hulp");
    helpButton.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    helpButtonMouseClicked(e);
    }
    });
    contentPanel.add(helpButton);
    helpButton.setBounds(330, 440, 80, helpButton.getPreferredSize().height);

    //---- Afrikaans ----
    Afrikaans.setText("Afrikaans");
    Afrikaans.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    AfrikaansMouseClicked(e);
    }
    });
    contentPanel.add(Afrikaans);
    Afrikaans.setBounds(5, 440, 90, Afrikaans.getPreferredSize().height);

    //---- Engels ----
    Engels.setText("Engels");
    Engels.addMouseListener(
    new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
    EngelsMouseClicked(e);
    }
    });
    contentPanel.add(Engels);
    Engels.setBounds(105, 440, 90, Engels.getPreferredSize().height);

    //---- label15 ----
    label15.setText("text");
    label15.setIcon(new ImageIcon("C:\\Documents and Settings\\Jonannes van Zyl\\My Documents\\My Pictures\\lawninsky1680x1050tl6.jpg"));
    contentPanel.add(label15);
    label15.setBounds(0, 0, 415, 470);

    { // compute preferred size
    Dimension preferredSize = new Dimension();
    for(int i = 0; i < contentPanel.getComponentCount(); i++) {
    Rectangle bounds = contentPanel.getComponent(i).getBounds();
    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
    }
    Insets insets = contentPanel.getInsets();
    preferredSize.width += insets.right;
    preferredSize.height += insets.bottom;
    contentPanel.setMinimumSize(preferredSize);
    contentPanel.setPreferredSize(preferredSize);
    }
    }
    dialogPane.add(contentPanel, BorderLayout.CENTER);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
    // Generated using JFormDesigner non-commercial license
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel Ldatum;
    private JTextField Dag;
    private JTextField Maand;
    private JTextField Jaar;
    private JLabel Ldag;
    private JLabel Lmaand;
    private JLabel Ljaar;
    private JLabel Ldagloon;
    private JTextField Dagloon;
    private JLabel Lnaam;
    private JLabel Laantaldae;
    private JLabel Lbyvoegings;
    private JLabel Laftrekkings;
    private JLabel Lgewerk;
    private JTextField naam1;
    private JTextField naam2;
    private JTextField naam3;
    private JTextField naam4;
    private JTextField naam5;
    private JTextField naam6;
    private JTextField naam7;
    private JTextField naam8;
    private JTextField naam9;
    private JTextField naam10;
    private JTextField dae1;
    private JTextField dae2;
    private JTextField dae3;
    private JTextField dae4;
    private JTextField dae5;
    private JTextField dae6;
    private JTextField dae7;
    private JTextField dae8;
    private JTextField dae9;
    private JTextField dae10;
    private JTextField by1;
    private JTextField by2;
    private JTextField by3;
    private JTextField by4;
    private JTextField by5;
    private JTextField by6;
    private JTextField by7;
    private JTextField by8;
    private JTextField by9;
    private JTextField by10;
    private JTextField af1;
    private JTextField af2;
    private JTextField af3;
    private JTextField af4;
    private JTextField af5;
    private JTextField af6;
    private JTextField af7;
    private JTextField af8;
    private JTextField af9;
    private JTextField af10;
    private JLabel Ltotaal;
    private JTextField tot1;
    private JTextField tot2;
    private JTextField tot3;
    private JTextField tot4;
    private JTextField tot5;
    private JTextField tot6;
    private JTextField tot7;
    private JTextField tot8;
    private JTextField tot9;
    private JTextField tot10;
    private JButton Berekentot;
    private JButton Berekenlone;
    private JButton Veldskoon;
    private JSeparator separator2;
    private JButton okButton;
    private JButton helpButton;
    private JButton Afrikaans;
    private JButton Engels;
    private JLabel label15;
    // JFormDesigner - End of variables declaration //GEN-END:variables
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Johanis View Post
    Thanx but that still doesnt fix my error...:(
    I'm confused how my suggestion doesn't fix your error when you stated that berkley's recommendation -- which is the same as mine -- did?

    Also, it is unlikely that anyone will read all that unformatted code. Please read my link on use of code tags, and also the one on creating an SSCCE

    Best of luck.

  7. #7
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    No it did I was probably confused...Thanx for the positive feedback...! could you not TRY to have a look at it???

  8. #8
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    How do i format it?

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Johanis View Post
    How do i format it?
    There are four links in my signature, and the top one is on how to use code tags. The other useful one for you will be how to create an SSCCE which means a small compilable and runnable program that demonstrates your problem.

    Luck!

  10. #10
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Im a bit confused about your request.

    When you say "run again" do you mean you want to completely get rid of the JFrame and make a new instance?

    If I were you, id reuse the same frame, just "reset" all the components inside it (clear input etc)

    This could be done by making a method - "reset()", and calling it in the "OK button"s onAction event.
    Java Code:
    int answer = JOptionPane.showConfirmDialog(frame, "restart?");
    if (answer == JOptionPane.YES_OPTION) {
        // User clicked YES.
        reset();
    } else if (answer == JOptionPane.NO_OPTION) {
        // User clicked NO.
        System.exit (0);
    }

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I strongly suggest you get rid of many of those JTextFields that are arranged in a table-like structure, and instead use a JTable. It will simplify your code immensely. If you don't feel comfortable using JTables, then at least use arrays of JTextFields which will allow you to do most all of your calculations in one block in a for loop.

  12. #12
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    berkeleybross: Thanx that code is very useful, but I must incorporate a loop in there somewhere, like to let the program run again, or else I lose like allot of marks!!

    Fubarable: Thanx I will go and study the SSCCE...I will also remember to use Jtable layout in the future for something like this...But I need a LOOP!:D

  13. #13
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    [QUOTE=Johanis;153091]berkeleybross: Thanx that code is very useful, but I must incorporate a loop in there somewhere, like to let the program run again, or else I lose like allot of marks!!

    Fubarable: Thanx I will go and study the SSCCE...I will also remember to use Jtable layout in the future for something like this...But I need a LOOP!:D

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You don't need a loop to have the GUI run again as it will continue to run and recalculate whenever data is changed. What you need is a LOOP to do your actual calculations and to do that you need an ARRAY, here an array of JTextFields. Entiendes?

  15. #15
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Talking

    Thanx berkeleybross!! That code works beautifully!! My teacher was very impressed with the work!

    And thanx Fubarable fot all the advice and links...You guys are AWSOME!!!!!D

  16. #16
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Glad to have helped :)
    you can mark the thread as solved, top right of the page (i think its under thread options or something)

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Just to show you an example of this being done with a JTable, and no, you can't turn this in....

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    import javax.swing.table.*;
    
    @SuppressWarnings("serial")
    public class LoneB extends JPanel {
       public static final String[] COLUMNS = {"Name", "Days Worked", "Addition", "Deduction", "Total"};
       
       private DefaultTableModel tablemodel;
       private JTable table;
       private JTextField wagesPerDayField = new JTextField("100", 10);
    
       public LoneB() {
          tablemodel = createModel();
          table  = new JTable(tablemodel) {
             // user can directly edit all cells except those in the last row.
             public boolean isCellEditable(int row, int column) {
                return (column < COLUMNS.length - 1);
             }
          };
          
          JPanel wagesPerDayPanel = new JPanel();
          wagesPerDayPanel.add(new JLabel("Wages Per Day: "));
          wagesPerDayPanel.add(wagesPerDayField);
          wagesPerDayPanel.add(Box.createHorizontalGlue());
          
          int blGap = 15;
          setLayout(new BorderLayout(blGap, blGap));
          setBorder(BorderFactory.createEmptyBorder(blGap, blGap, blGap, blGap));
          JScrollPane scrollpane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
          JViewport viewport = scrollpane.getViewport();
          Dimension d = viewport.getPreferredSize();
          viewport.setPreferredSize(new Dimension(d.width, d.height / 2));
    
          JButton sumButton = new JButton("Calculate");
          sumButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                calculateButtonActionPerformed();
             }
          });
          JPanel buttonPanel = new JPanel();
          buttonPanel.add(sumButton);
    
          add(scrollpane, BorderLayout.CENTER);
          add(buttonPanel, BorderLayout.SOUTH);
          add(wagesPerDayPanel, BorderLayout.NORTH);
       }
    
       private DefaultTableModel createModel() {
          DefaultTableModel model = new DefaultTableModel(COLUMNS, 10) {
             @Override
             // the table holds a column of String, then three columns of Integers,
             // then a final column of Double
             public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex > 0 && columnIndex < COLUMNS.length - 1) {
                   return Integer.class; // the middle columns
                } else if (columnIndex == COLUMNS.length - 1) {
                   return Double.class; // the last column
                }
                // for the first column of string
                return super.getColumnClass(columnIndex);
             }
    
          };
          return model;
    
       }
    
       private void calculateButtonActionPerformed() {
          double wagesPerDay = 0;
          try {
             wagesPerDay = Double.parseDouble(wagesPerDayField.getText());
          } catch (NumberFormatException e) {
             return;
          }
          for (int row = 0; row < tablemodel.getRowCount(); row++) {
             double result = 0.0;
             int intValue = 0;
             for (int column = 1; column < tablemodel.getColumnCount() - 1; column++) {
                Integer value = (Integer) tablemodel.getValueAt(row, column);
                if (value != null) {
                   intValue = value.intValue();
                   switch (column) {
                   case 1:
                      result += wagesPerDay * intValue;
                      break;
                   case 2:
                      result += intValue;
                      break;
                   case 3:
                      result -= intValue;
                      break;
    
                   default:
                      break;
                   }
                }
             }
             tablemodel.setValueAt(result, row, COLUMNS.length - 1);
          }
       }
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("LoneB");
          frame.getContentPane().add(new LoneB());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }

  18. #18
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Talking

    Quote Originally Posted by Fubarable View Post
    Just to show you an example of this being done with a JTable, and no, you can't turn this in....
    [/code]
    OMW!! You are so awsome! I can not tell you how grateful I am. I see now that using the Jtable is allot easier than inserting all those textfields. The thing is: This is the first big GUI project I am doing and I know nothing about using GUI let alone Jtabel. Doing it the way I did it looked easier but clearly is not. I am using JForm Designer to do this and the table didn't look the same, but stil thanx allot! I couldn't find a big enough smiley to put in haha!

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Yeah, but if you turn that in, the instructor will know that you didn't write it -- which is the only reason I posted it.

  20. #20
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default

    Hey Fubarable...one last question: How do I implement the code you used to make that the user can not edit the total coulomb?

    // user can directly edit all cells except those in the last row.
    public boolean isCellEditable(int row, int column) {
    return (column < COLUMNS.length - 1);

    How long did it take to write the program that you gave me?
    Last edited by Johanis; 11-02-2010 at 05:59 PM.

Similar Threads

  1. Error: it exspected a '.'
    By zoe in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 01:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •