email me at borlaj@portlandschools.org

Loading
notes previous (11/<11) submit the dump links  
 

Intro to Java

 

Create a new project - I recommend saving all these bluej files in a bluej folder (on flash or h: drive) and name everything appropriate. Maybe create a new project called IntroActivities

 

Applications

We are going to create a simple application. Use this as reference for printing out.

  1. Create a new class. Name it SimpleApp
  2. In the application code, delete
    • all the methods but sampleMethod

  3. Update the comment in the beginning
  4. Make it say a bunch of different line
  5. Advanced - try to make it repeat

 

Applets

We are going to create a simple graphical applet.

  1. Create a new class and select applet. Name it SimpleDrawing
  2. In the applet code, delete
    • all the methods but paint (there are 6 methods)
    • the global variable x
  3. Update the comment in the beginning
  4. Make a simple drawing with atleast 4 different objects and colors. Use the graphics api for help.

User Interface

We are going to create a simple gui.

  1. Create a new applet. Name it SimpleGui
  2. In the applet code, in the init method add the code below:
        Container con = getContentPane();
        con.setBackground(Color.green);
        con.setLayout (new FlowLayout() );
        con.add(new JTextField(20));
        con.add(new JButton ("Hit Me"));

 

  1. Update the comment in the beginning
  2. Try changing the color adding some new text fields and buttons and other items like below:
con.add(new JSlider(JSlider.HORIZONTAL,1,10,1));  //for a slider
con.add(new JTextArea(3,20)); //for a text area
con.add(new JProgressBar(1,10)); //for a progress bar

//FOR A MENU:
JMenuBar menuBar = new JMenuBar();
menuBar.add(new JMenu("A Menu"));
menuBar.add(new JMenu("Two"));
menuBar.add(new JMenu("Three"));
setJMenuBar(menuBar);
    

Heres a link to other components that you could use in your gui.

 

Stock quote:

Create 2 new classes called In and StockQuote -> copy the contents from In and StockQuote into your program.

Now lets use it.

 

3D Rotation

Create a new class (call it anything) and replace the code with this code and run.