Results 1 to 3 of 3

Thread: Array problems

  1. #1
    Hosticus is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default Array problems

    Hi,

    I can't resolve "newWord()" ..

    Help me please !!!


    //Start.java
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;

    public class Start {
    private static JFrame mainFrame;

    public static void main(String[] args) {
    mainFrame = new JFrame("WoordenBoek 1.0");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);
    View view = new View();
    mainFrame.getContentPane().add(view);
    mainFrame.setSize(400, 200);
    mainFrame.setResizable(false);
    mainFrame.setVisible(true);
    }
    }

    class View extends JPanel implements ActionListener {
    private boolean saved = true;

    private int Nummer = 0;
    private String[]D;
    private String[]Dat = {"","","",""};
    private final String[]Dat0 = {"Vanessa Johanna Hantson","Vriendin","Personen","Leer haar kennen en oordeel dan!"};
    private final String[]Dat1 = {"Ali Isin","Vriend","Personen","Leer hem kennen en oordeel dan!"};
    private final String[]Dat2 = {"Jochen Hantson","Broertje","Personen","Leer hem kennen en oordeel dan!"};
    private final String[]Dat3 = {"Deniz Isin","Broertje","Personen","Leer hem kennen en oordeel dan!"};
    private String[][]Data = {Dat0, Dat1, Dat2, Dat3};

    private JPanel controlPanel = new JPanel();
    private JPanel viewPanel = new JPanel();
    private JPanel labelPanel = new JPanel();
    private JPanel fieldPanel = new JPanel();

    private final JButton prevButton = new JButton(" prev ");
    private final JButton nextButton = new JButton(" next ");
    private final JButton newButton = new JButton(" new ");
    private final JButton saveButton = new JButton(" save ");
    private final JButton exitButton = new JButton(" exit ");

    private final String wordString = "WORD: ";
    private final String groupString = "GROUP: ";
    private final String categoryString = "CATEGORY: ";
    private final String descriptionString = "DESCRIPTION: ";

    private final JLabel wordLabel = new JLabel(wordString);
    private final JLabel groupLabel = new JLabel(groupString);
    private final JLabel categoryLabel = new JLabel(categoryString);
    private final JLabel descriptionLabel = new JLabel(descriptionString);

    private JTextField wordText = new JTextField(20);
    private JTextField groupText = new JTextField(20);
    private JTextField categoryText = new JTextField(20);
    private JTextField descriptionText = new JTextField(60);

    View() {
    D = Dat0;

    labelPanel.setLayout(new GridLayout(0, 1));
    labelPanel.add(wordLabel);
    labelPanel.add(groupLabel);
    labelPanel.add(categoryLabel);
    labelPanel.add(descriptionLabel);

    fieldPanel.setLayout(new GridLayout(0, 1));
    wordText.setText(D[0]);
    fieldPanel.add(wordText);
    groupText.setText(D[1]);
    fieldPanel.add(groupText);
    categoryText.setText(D[2]);
    fieldPanel.add(categoryText);
    descriptionText.setText(D[3]);
    fieldPanel.add(descriptionText);

    viewPanel.setLayout(new BoxLayout(viewPanel, BoxLayout.X_AXIS));
    viewPanel.add(labelPanel);
    viewPanel.add(fieldPanel);

    controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS));
    controlPanel.add(prevButton);
    prevButton.addActionListener(this);
    controlPanel.add(nextButton);
    nextButton.addActionListener(this);
    controlPanel.add(newButton);
    newButton.addActionListener(this);
    controlPanel.add(saveButton);
    saveButton.addActionListener(this);
    controlPanel.add(exitButton);
    exitButton.addActionListener(this);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(viewPanel);
    add(controlPanel);
    }

    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == prevButton) prevWord();
    if(e.getSource() == nextButton) nextWord();
    if(e.getSource() == newButton) newWord();
    if(e.getSource() == saveButton) saveWord();
    if(e.getSource() == exitButton) exitWB();
    }

    private void exitWB() { if(saved)System.exit(0); else warnExit(); }

    private void newWord() {
    Nummer = Data.length-1;
    Data[Nummer] = Dat;
    renew(Nummer);
    }

    private void nextWord() {
    if((Data.length-2) >= Nummer) {
    Nummer++;
    renew(Nummer);
    }
    }

    private void prevWord() {
    if(1 <= Nummer) {
    Nummer--;
    renew(Nummer);
    }
    }

    private void saveWord() {}

    private void warnExit() {
    JDialog JD = new JDialog();
    JD.setAlwaysOnTop(true);
    JD.setSize(300, 100);
    JD.add(new JLabel("PLEASE SAVE BEFORE QUITING!"));
    JD.setVisible(true);
    }

    private void renew(int nummer) {
    D = Data[nummer];
    wordText.setText(D[0]);
    groupText.setText(D[1]);
    categoryText.setText(D[2]);
    descriptionText.setText(D[3]);
    repaint();
    }
    }
    //END.

    Thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    You don't seriously expect to be able to invoke a method that doesn't exist? Start learning Java here:
    The Java™ Tutorials

    db

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

    Default

    I would not use a 2D array of String here, and in fact I wouldn't use an Array at all to hold the data. Better to create a class, say called Dat that has String fields for word, group, category, and description. I'd then use an ArrayList<Dat> as my data structure. Then when the user enters their data and presses Save, it's easy to create a new Dat object and place it into the ArrayList. Best of luck.

Similar Threads

  1. Problems displaying and array of JPanels
    By dousedfirepants in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 05:47 AM
  2. array problems need your help ASAP!
    By notherand in forum New To Java
    Replies: 1
    Last Post: 06-29-2008, 08:59 PM
  3. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  4. Replies: 1
    Last Post: 12-14-2007, 07:25 AM
  5. problems with array index
    By mary in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 04:30 PM

Posting Permissions

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