6098 comments
2357 subscribers
6259 on Twitter
Subscribe! Feed reader E-mail

Sample array code

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**
 * Demo class for arrays
 * @author Sacha Chua (sacha@free.net.ph)
 * @date 22-Feb-2004
 */

public class ReallySimpleAddressBook extends Applet implements ActionListener
{
    private Button set;
    private Button show;
    private TextField index;
    private TextField name;
    private String names[];

    public void init()
    {
        names = new String[10];
        set = new Button("Set");
        show = new Button("Show");
        set.addActionListener(this);
        show.addActionListener(this);

        index = new TextField();
        name = new TextField();
        Label label1 = new Label("Index:");
        Label label2 = new Label("Name:");

        setLayout(new GridLayout(3, 2));
        add(label1);
        add(index);
        add(label2);
        add(name);
        add(set);
        add(show);

    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == set)
        {
            int i = Integer.parseInt(index.getText());
            names[i] = name.getText();
        }
        if (e.getSource() == show)
        {
            int i = Integer.parseInt(index.getText());
            name.setText(names[i]);
        }
    }
}

../../tmp/ReallySimpleAddressBook.java

Short URL: http://sachachua.com/blog/p/1748
  • http://www.friendster.com Brigette

    can you site an example of program using 4 dimensional arrays

On This Day...

  • 2013: Seeing the futures — I often imagine different futures, sketching them out on paper or in those moments right before or after dreaming. It’s [...]
  • 2012: People-centered entrepreneurship — Practically all Many of the books I’m reading about entrepreneurship assume that you start with a big idea for a product [...]
  • 2011: Kaizen: Thinking about presentations — I’ve just finished a presentation (The ITSC Guide to Conference Awesomeness) and I’ve got a few presentations coming up: Remote Presentations [...]
  • 2011: How I spent my Family Day weekend — New recipes: chapati, curried chickpeas, vegetable biryani (from sauce), Tex-mex lasagna Lots of time spent putting together presentations. Worth it, though! [...]
  • 2010: Seeds — It was sunny and almost spring-like on Sunday. I rode my bicycle 5km to the Artscape Wychwood Barns, shedding my [...]
  • 2009: LifeCampTO: Tweaking the plan! — Yesterday, Jordan Baker and I had a great conversation about how to make LifeCampTO even better. We wanted to figure [...]
  • 2007: Yes to social networking, no to MLM — Because of a matter involving some people I know, I ended up taking a look at Success University. I have to [...]
  • 2006: ‘tinerant Tuesday — I firmly believe that the best way to get to know a city is to wander around. With that in mind, [...]
  • 2006: Boston Science Museum — I cannot resist science museums. I am endlessly amused by models and hands-on experiments. As a reward for good behavior or [...]
  • 2005: Watched kabuki — Watched one act of a kabuki play at http://www.kabuki-za.co.jp/ . It was _beautiful_. Props to dagbrown for that excellent idea. Also, [...]
  • 2005: Baguio plans — how's this plan leave manila thrusday night be here friday morning have your talk saturday afternoon be in manila [...]
  • 2005: Geek Love — Revision from Dominique Cimafranca: One of the hallmarks of the stereotypical male computer nerd is his ineptitude with members of the opposite [...]
  • 2004: YASD: Don’t cast sleep on the priest! — Thought I’d help my pet baby green dragons out by casting sleep on the priest. This, apparently, is a Very [...]
  • 2004: CS161 Finals — The following students are to take the CS161 final exam on Thursday. They can e-mail me at sacha@free.net.ph to find out [...]
  • 2004: Exemptions for CS161 — No MIS student qualified for exemption.
  • 2004: Fantastic news! Wonderful news! Excellent news! — We get to postpone finals for juniors in CS161 to the normal time. Wheee! I feel so much better now. Of course, [...]
  • 2004: “View From the Alpha Geek” — From ACM Technews: Programmer Rael Dornfest keeps track of IT innovation and innovators as part of his job putting together O’Reilly & [...]
  • 2004: “Inventors Strut Stuff at Demo Show” — From ACM Technews: Dozens of high-tech innovations, ranging from small PCs to blogging tools to “augmented reality” software, were spotlighted at the [...]
  • 2003: my dad and his vaio — tech — So my dad has this really sweet Vaio U1. I walked into the room and saw him using it… to play [...]
  • 2003: Finished “The Human Condition” — school — Only one ream of paper to go. My highlighter looks like it’s running a bit low on ink. I want to [...]
  • 2003: back to work — school — Armed with my makeshift strawberry sugar-er and my trusty highlighter, I return to work.
  • 2003: sugar-coated strawberries — personal — The strawberries are nothing spectacular – a bit on the old side, with strange dark spots – but hey, they’re strawberries. [...]
  • 2003: a ream of arendt — school — I still have to go through a ream of Arendt later… Ah well.
  • 2003: done with the smaller readings — school, tips — I’ve come to appreciate the value of light yellow highlighters, but I still refuse to use them on anything but temporary [...]
  • 2003: hermit mode — personal — I think it’s about time I resumed hermit mode.
  • 2003: not going to party — personal — My mother strongly feels that I shouldn’t go to the party later, since my finals are next week after all. I [...]
  • 2003: gospel exercise — school — Okay, the gospel exercise is more or less done. Whew! That’s out of the way.

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!