up

Our Computing Environment

  1. Log in: Connect to STDSUN (Solaris), and fill the requested information in the fields of the login window [more on passwords]

  2. Open two windows: Netscape, Terminal.

  3. If you read the instructions from the handout, enter with the Netscape browser the web page

    to find the rest of the instructions.

  4. Download the attached code ‘draw.java’ through your browser (by clicking on the icon with the right button of the mouse, and saving it into your directory).

  5. Our platform uses the Unix operating system. The following are examples of recognizable commands.

    File names consist of letters, digits, and underscores

    Open the terminal window and issue the four leading commands from the above list.

  6. Email the file ‘draw.java’ to yourself.

  7. Issue the instruction ‘cat .subscriptions’ in the terminal window.

    If the entry ‘JDK-CURRENT’ is not shown in the output, setup java now.

  8. Compile the file with the command ‘javac draw.java’.

  9. View the outcome with the command ‘appletviewer draw.java &’.

  10. Copy the file with the unix command ‘cp draw.java mydraw.java

  11. Check the outcome with the unix command ‘ls’.

  12. Compile the new file--you should get error messages.

  13. Create documentation for your program with the command line ‘javadoc -package draw.java’, and inspect the output at ‘draw.html’ with your browser.

Notes:

  1. You are free to come to the lab any time to practice your programming.
  2. The cis account also provides you an email account. If your user-id is ‘xxxx’ then your email address is ‘xxxx@cis.ohio-state.edu’. The command line ‘pine’ may be used to bring up a menu-driven email reader (home page, tutorial, tutorial).
draw.java
 /*
   <applet code="draw.class"
   width="400" height="350"></applet>
 */
 
 
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 
 public class draw extends JApplet implements ActionListener {
 
    Container myScreen;
    JButton darwButton;
    MyCanvas myCanvas;
 
    int currPic;
    String choice;
 
 public void init(){
 
   myScreen=getContentPane();
   myScreen.setLayout(new FlowLayout());
 
   darwButton=new JButton("draw");
   myScreen.add(darwButton);
 
   myCanvas=new MyCanvas();
   myCanvas.setSize(300,300);
   myScreen.add(myCanvas);
 
   darwButton.addActionListener(this);
   currPic =1;
 }                                       //*** end init
 
 public void actionPerformed(ActionEvent e){
   choice=JOptionPane.showInputDialog(
      "1:  Lines\n" +
      "2:  Ovals"
   );
   try{ currPic =Integer.parseInt(choice); }
   catch(NumberFormatException ex){currPic =10;}
   myCanvas.repaint();
 }                                       //*** end actionPerformed
 
 public class MyCanvas extends Canvas{
 
   public void paint(Graphics g){
     g.setColor(Color.black);
     g.fillRect(0,0,480,480);
     g.setColor(Color.white);
     switch(currPic) {
       case 1:
              for(int i=0;i<10;i++) {
                g.drawLine(10,10,250,10+i*30);
              }
              break;
       case 2:
            for(int i=0;i<10;i++) {
                g.drawOval(10+i*10,10+i*10,50+i*10,50+i*10);
              }
         break;
       default:
       }
   }
 }                                    //*** end MyCanvas
 }
cis221 tutolial for unix | Unix (UTS) | cis tutorial for environment setting | OSU-CIS Computer User Guide

up