Help with RMI using inheritance program

Hi all, im having trouble starting (and finding info on how to) to convert this program to use RMI. I have just completed re-structuring the program to use extended inheritance along with a Access Database.
Whats the first step i need to take.
Any help will be much appreciated. THANKS ALL
import java.sql.*;
import javax.swing.*;
import java.util.*;
public class Database {
   public java.sql.Connection connection;
   public void connect() 
      String url = "jdbc:odbc:groupTask2";  
      String username = "admin";   String password = "teama";
      // Load the driver to allow connection to the database
      try {
         Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
         connection = java.sql.DriverManager.getConnection(url, username, password );
      catch ( ClassNotFoundException cnfex ) {
         System.err.println("Failed to load JDBC/ODBC driver->"  + cnfex);
      catch ( SQLException sqlex ) {
         System.err.println( "Unable to connect->" + sqlex );
   public void showTeams()
      java.sql.Statement statement;
      java.sql.ResultSet resultSet;
      try {
         String query = "SELECT Team_name FROM Team_class";
         statement = connection.createStatement();
         resultSet = statement.executeQuery( query );
         displayResultSet( resultSet );
         statement.close();
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
   public void showPlayers()
      java.sql.Statement statement;
      java.sql.ResultSet resultSet;
      String team = null;
      try {
         String s = JOptionPane.showInputDialog("Please select Team: \n\n1. Panthers \n2. Quails \n3. Bears \n4. Nevils \n ");
         int a = Integer.parseInt(s);
         switch (a){
             case 1: team = "Panthers";
                     break;
             case 2: team = "Quails";
                     break;
             case 3: team = "Bears";
                     break;
             case 4: team = "Nevils";
                     break;
         String query = "SELECT player_id, First_name, Last_name FROM Player_class WHERE Team_name LIKE '"+team+"'";
         statement = connection.createStatement();
         resultSet = statement.executeQuery( query );
         displayResultSet( resultSet );
         statement.close();
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
   public void update()
      java.sql.Statement statement;
      java.sql.Statement statement2;
      java.sql.ResultSet resultSet;
      String field = null;
      try {
         String a = JOptionPane.showInputDialog("Please Enter the player ID:");
         int id = Integer.parseInt(a);
         String b = JOptionPane.showInputDialog("Which field would you like to update? \n\n1. First name \n2. Last name \n3. Address \n ");
         int choice = Integer.parseInt(b);
         switch (choice){
             case 1: field = "First_name";
                     break;
             case 2: field = "Last_name";
                     break;
             case 3: field = "address";
                     break;
         String val = JOptionPane.showInputDialog("Please enter new " +field);
         String query = "UPDATE Player_class SET "+field+" = '"+val+"' WHERE player_id = "+id;
         statement = connection.createStatement();
         statement.executeQuery( query );
         statement.close(); 
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
   public void displayResultSet( ResultSet rs )
      throws SQLException
      // position to first record
      boolean moreRecords = rs.next();  
      // If there are no records, display a message
      if ( ! moreRecords ) {
            System.out.println( "ResultSet contained no records" );
            return;
      System.out.println( "" );
      try {
         java.sql.ResultSetMetaData rsmd = rs.getMetaData(); 
         // Get column heads
         for ( int i = 1; i <= rsmd.getColumnCount(); ++i ) {
             System.out.print(rsmd.getColumnName( i ) + "\t");
         System.out.println();
         do {// get row data
              displayNextRow( rs, rsmd );
         } while ( rs.next() );
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
   public void displayNextRow( ResultSet rs, 
                              ResultSetMetaData rsmd )
       throws SQLException
      for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
         switch( rsmd.getColumnType( i ) ) {
            case java.sql.Types.VARCHAR:
                  System.out.print (rs.getString( i )+"\t\t" );
               break;
            case java.sql.Types.INTEGER:
                  System.out.print ( rs.getLong( i ) + "\t\t") ;
               break;
            default: 
               System.out.println( "Type was: " + 
                  rsmd.getColumnTypeName( i ) );
         System.out.println();
   public void shutDown()
      try {
         connection.close();
      catch ( SQLException sqlex ) {
         System.err.println( "Unable to disconnect->" + sqlex );
   public static void main( String args[] ) 
       int sel = 0;
       Menu M = new Menu();
       Database app = new Database();
       sel = M.mainmenu(sel);
       while (sel > 0 && sel < 5){
       switch (sel){
           case 1: app.connect();
                   app.showTeams();
                   app.shutDown();
                   sel = M.mainmenu(sel);
                   break;
           case 2: app.connect();
                   app.showPlayers();
                   app.shutDown();
                   sel = M.mainmenu(sel);
                   break;
           case 3: app.connect();
                   app.update();
                   app.shutDown();
                   sel = M.mainmenu(sel);
                   break;
class Menu{ 
    int choice = 0;
    int temp = 0; 
    public Menu(){
    public int mainmenu(int val){ 
        String a = JOptionPane.showInputDialog("TEAM MENU \n\nPlease select an option by entering " + 
                "the corresponding number: \n\n1. Display Teams \n2. Show Players \n3. Update a Player \n4. Search \n "); 
        val= Integer.parseInt(a); 
        return val; 
    public int setChoice(int val){
        choice = val;
        return choice;

Well, I'd say a starting point is to split the functionality into "client" and "server". This will wind up as two programs, the client making - remote - requests of the server.
A fairly natural way would be to assign viewing/display to the client, direct access to the database to the server. So then you have to figure out
o what kinds of requests can go acrross the divide.
o what kind of data will be returned.
This may not be that easy, because things that the server can do easily (like I/O) cnnot be carried back and forth in RMI calls.)

Similar Messages

  • Help with constructors using inheritance

    hi,
    i am having trouble with contructors in inheritance.
    i have a class Seahorse extends Move extends Animal
    in animal class , i have this constructor .
    public class Animal() {
    public Animal (char print, int maxage, int speed) {
    this.print = print;
    this.maxage = maxage;
    this.speed = speed;
    public class Move extends Animal {
    public Move(char print, int maxage, int speed)
    super(print, maxage, speed); //do i even need this here? if i dont i
    //get an error in Seahorse class saying super() not found
    public class Seahorse extends Move {
    public Seahorse(char print, int maxage, int speed)
    super('H',10,0);
    please help

    It's not a problem, it's how Java works. First, if you do not create a constructor in your code, the compiler will generate a default constructor that does not take any arguments. If you do create one or more constructors, the only way to construct an object instance of the class is to use one of the constructors.
    Second, when you extend a class, your are saying the subclass "is a" implementation of the super class. In your case, you are saying Move is an Animal, and Seahorse is a Move (and an Animal as well). This does not seem like a good logical design, but that's a different problem.
    Since you specified that an Animal can only be constructed by passing a char, int, and int, that means that a Move can only be constructed by calling the super class constructor and passing a char, int, and int. Since Move can only be constructed using a char, int and int, Seahorse can only be constructed by calling super(char, int, int);.
    It is possible for a subclass to have a constructor that does not take the same parameters as the super class, but the subclass must call the super class constructor with the correct arguments. For example, you could have.
    public Seahorse() {
       super('S',2,5);
    }The other problem is, Move does not sound like a class. It sounds like a method. Perhaps you might have MobileAnimal, but that would only make sense if there was a corresponding StationaryAnimal. Your classes should model your problem. It's hard to image a problem in which a Seahorse is a Move, and a Move is an Animal. It makes more sense for Animals to be able to move(), which allows a Seahorse to move differently compared to an Octopus.

  • Help with RMI tutorial (and Eclipse)

    Hi!
    I need a little help with RMI tutorial. I have all source files from tutorial downloaded, but I never did anything like this and don't know, how to run it. I somehow did Building a JAR File of Interface Classes from [http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/rmi/compiling.html], but got stuck on simple HTTP server, I didn't understand, what to do.
    Bonus question: is it possible to do those commands from Eclipse? How?
    Thanks a lot!

    It seems that the example provided (in the link) requires a web serverNo it doesn't. It requires an HTTP server.
    tomcat will be a better option which you can useThe Apache HTTP server might be more to the point.
    But If you are new to RMI and need to understand the exact flow of RMI I think this will not be a better exercise to start withI agree. I would get it running without the codebase feature. This isn't as widely used as you might think, and anyway it is a deployment option not something you need to engage with much when developing.
    @OP: ignore the HTTP stuff and the codebase feature and build 3 JAR files:
    (a) the common stuff (remote interface, stubs if any, and any classes referecned by the remote interface)
    (b) the server (the remote object itself and anything server-side it uses)
    (c) the client.
    The common JAR file should be deployed to both the server and the client, and both the other JARs should name it in their Class-Path entry in the manifest.

  • Bizzare behavior with RMI using the localhost

    I'm still new to RMI and I'm observing some strange behavior with RMI.
    I'm using RMI as a communication protocol in a client/server database application. Since I don't have access to a network at the moment I was running the application on a single host and using the local host parameter to test my RMI code.
    In my code if I do a naming lookup on the local host and it works as I would expect it to. (Note before this code fragment runs I've all ready started the rmi registry and bound the RemoteDatabase to it.)
    try{
    String name = "rmi://" + "127.0.0.1" +":"+1099+"/RemoteDatabase";
    thedb = (RemoteDB)Naming.lookup(name);
    }catch
    Now if I replace "127.0.0.1" with a garbage value such as "12453" it still works!
    This is not the behavior I expected. I expected that the Naming.lookup would throw a exception of some kind.
    Can any one explain this behavior?
    The reason I would like this to work as I expected is that in my application the IP address string and port number are variables that I allow the user to set through a dialog. If the user puts in a garbage string for the IP address I want to catch the exception and display an appropriate warning dialog to the user. I can't seem to do that since the Naming.lookup() for a garbage IP address doesn't seem to throw any exception that I have been able to detect.
    I've actually observed even stranger behavior. If I use a garbage string such as 124.4.1.2, which is invalid IP address, the Naming.lookup() will throw an exception. If I put in a garbage string such as "aaaaaa" for the IP address the Naming.lookup() throws an exception. This is the behavior I would expect.
    However as I mentioned if I use a string such as "12345" for the IP address the code works! This seemingly inconsistent behavior is driving me nuts so if any of you RMI gurus out there can help me out I would very much appreciate it.
    Thanks in advance.

    Hi, there.
    lookup uses URI parsing so the fact that your using numbers being equivalent to localhost seems to be due to the fact that that is an invalid host according to the javadocs for the getHost primitive attached below(marked the most important parts). In this case returning null is interpreted as absent , therefore => localhost. Nothing about the port! Maybe you can take it from here. Seems you'll have to make some user input validation yourself, in your application. Hope I haven't missed anything.
    Good luck.
    Nuno
    getHost
    public String getHost()Returns the host component of this URI.
    The host component of a URI, if defined, will have one of the following forms:
    A domain name consisting of one or more labels separated by period characters ('.'), optionally followed by a period character. Each label consists of alphanum characters as well as hyphen characters ('-'), though hyphens never occur as the first or last characters in a label.
    The last, or only, label in a domain name begins with an alpha character.
    A dotted-quad IPv4 address of the form digit+.digit+.digit+.digit+, where no digit sequence is longer than three characters and no sequence has a value larger than 255.
    An IPv6 address enclosed in square brackets ('[' and ']') and consisting of hexadecimal digits, colon characters (':'), and possibly an embedded IPv4 address. The full syntax of IPv6 addresses is specified in RFC 2373: IPv6 Addressing Architecture.
    The host component of a URI cannot contain escaped octets, hence this method does not perform any decoding.
    Returns:
    The host component of this URI, or null if the host is undefined
    ********************************************************************

  • Please help with structure of my program

    I am hoping someone can help me with a motor control program that I am
    writing.  The program is too large to post here, but I attached a
    rough outline of the program.  I think the problem is with the
    higher level logic, so hopefully that will provide the necessary
    information. 
    I have a front panel with lots of buttons to control the motors (eg:
    power, stop, start).  There is an event structure that contains
    most of those buttons (power, start, etc), but if that structure is
    exectuting, the other buttons won't work.  I need to be able to
    stop the motors and exit at any time (for safety), so I made another
    event structure that contains the stop and exit buttons.  Is this
    the right way to do this?
    Also, I want all the loops in the program to run continually until the
    exit button is pressed.  Since the exit button actually calls
    exit.vi and closes the whole program, I just wired a F constant to the
    stop on the while loops so they never stop.  Could this be causing
    my problems? 
    Hopefully I provided enough information here, but if not, please write back and let me know.
    Thanks,
    Kasey
    PS. In case anyone wonders why the whole thing is in a sequence, I need
    it for other aspects of the program (safety lights, etc...).  I
    doubt it makes a difference, but I wanted to include it.
    Attachments:
    screenshot.jpg ‏258 KB

    This is the first time I have seen a case where it is useful to have two or more event structures in one program.  Since they are in separate parallel loops, I would think there would not be a problem.  I like the idea that the program can be stopped in the middle of an event, for safety reasons.  Great structure, Kasey.  The only thing I would add is to make sure that your exit vi gracefully shuts down the program.  Like if files or references are open, they get closed before terminating the vi.  Just be on the look out for race conditions since you have 3 events that can happen at one time.  One event might affect some indicator that is being handled by another event.  Also, instead of wiring a false to the other loops, maybe you could use local variables of one general stop boolean.  Since your exit vi stops all execution, it may not make much of a difference.
    - tbob
    Inventor of the WORM Global

  • Help with a Word Counting Program..

    I need some help with a program I am trying to write
    The program is being written in BlueJ.
    Im just starting the program and am completely confused on how I should write this...
    But here is what I have to do..
    I have to use a scanner to scan a Text file and count the # of Words the number of Vowels (including Y when it is) and the # of Palindromes (Word spelled same forward and Back) as well as which Palindromes are being used.
    It would be good to have a class to clean the text and a seperate class for the tasks...
    I do not want to use anything other than "If" statements and while loops (no "for" loops) and only use Printwriter as the output file writer.
    Thnx to anyone in advance

    I have a basic Vowel coding that doeswnt work...
    public class vowel{
    String word = "heyyou";
    String vowels = "aeiouy";
    int[] countv = new int[vowels.length()];
    int countv2;
    int i=0;
    if(i<word.length();) { i++ {
    if (int j=0 && j<vowels.length()) {
    return j++;
    if (word.charAt(i)==vowels.charAt(j)) {
    countV[j]++; countV2++;
    for (int i=0; i<vowels.length(); i++) {
    System.out.println("Vowel "vowels.charAt(i)" = "+vcnt);
    System.out.println("Consonants = "+(word.length()-vtot)); }
    I also have a basic Palindrome code that works as a boolean but I need to make it return what the palindromes are and how many of them are there. I wanna know how I would do this.
    public class Palindrome{
    public static boolean isPalindrome(String word) {
    int left = 0;
    int right = word.length() -1;
    while (left < right) {       
    if (word.charAt(left) != word.charAt(right)) {
    return false;
    left++;
    right--;
    return true;
    I would also like to know how to actually start writing the word counter.

  • Help with 7 segment led program

    hey, I need some help with my program. The program is supposed to make digital numbers display randomly with a possible decimal point in it. If the decimal # has a leading zero, then the zero needs to be not displayed. also, when you click the change color button, the numbers and decimal point are supposed to change to one of three preset colors. I've got the numbers changing colors, but I can't get the decimal point to change color, nor can I get the numbers to change randomly.
    package led7segment;
    import java.awt.event.*;
    import javax.swing.*;
    * Robert Lundahl
    * cs1410-002
    * @author Matthew Lohmeyer
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) throws InterruptedException {
            // TODO code application logic here
            JFrame.setDefaultLookAndFeelDecorated(true);
            MyJFrame mjf = new MyJFrame();
            while (true) {
                int deci = (int)(Math.random() * 3);
                int num = (int)(Math.random() * 1000);
                Digit.DisplayNumber(num, deci);
                Thread.sleep(4000);
    package led7segment;
    import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    * Robert Lundahl
    * cs1410-002
    * @author Matthew Lohmeyer
    public class MyJFrame extends JFrame implements ActionListener{
        private JButton jb1, jb2, jb3;
        Digit d1, d2, d3;
        Oval deci;
        Color c;
        Oval o1, o2, o3;
        public MyJFrame()
            super("LED Display");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBounds(50, 50, 500, 320);
            setVisible(true);
            setLayout(null);
    //        jb1 = new JButton("Down");
    //        jb1.setBounds(10,225, 75, 50);
    //        add(jb1);
    //        jb1.addActionListener(this);
            jb2 = new JButton("Change Color");
            jb2.setBounds(10,225, 200, 50);
            add(jb2);
            jb2.addActionListener(this);
            jb3 = new JButton("Exit");
            jb3.setBounds(250,225, 100, 50);
            add(jb3);
            jb3.addActionListener(this);
            d1 =new Digit(7);
            add(d1);
            d1.setBounds(10,10,120,190);
            d1.setVisible(true);
            d2 =new Digit(7);
            d2.setBounds(150,10,120,190);
            add(d2);
            d2.setVisible(true);
            d3 =new Digit(7);
            d3.setBounds(300,10,120,190);
            add(d3);
            d3.setVisible(true);
            o1 = new Oval(125, 160, 15, 15);
            o1.setVisible(true);
            add(o1, 0);
            o2 = new Oval(275, 160, 15, 15);
            o2.setVisible(true);
            add(o2, 0);
            o3 = new Oval(425, 160, 15, 15);
            o3.setVisible(true);
            add(o3, 0);
            repaint();
        public void actionPerformed(ActionEvent e) {
            Object j = e.getSource();
    //        if(j==jb1)
    //            d1.incDown();
    //            d2.incDown();
    //            d3.incDown();
            if(j==jb2)
                d1.changeColor();
                d2.changeColor();
                d3.changeColor();
                o1.changeColor();
            else if(j==jb3)
                d1.incUp();
                d2.incUp();
                d3.incUp();
    package led7segment;
    import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    * Robert Lundahl
    * cs1410-002
    * @author Matthew Lohmeyer
    public class Digit extends JComponent{
        Rectangle rect[] = new Rectangle[7];
        Oval o1[] = new Oval[7];
        private boolean decimal;
        private Color mycolor[] = new Color[]{Color.RED, Color.GREEN,  Color.BLUE};
        private int cindex = 0;
        private int increment =8;
        private Rectangle topRectangle = new Rectangle(23, 10, 66, 20);
        private Rectangle leftTopRectangle = new Rectangle(0, 13, 20, 76);
        private Rectangle leftBottomRectangle = new Rectangle(0, 92, 20, 76);
        private Rectangle bottomRectangle = new Rectangle(23, 151, 66, 20);
        private Rectangle rightBottomRectangle = new Rectangle(92, 92, 20, 76);
        private Rectangle rightTopRectangle = new Rectangle(92, 13, 20, 76);
        private Rectangle midRectangle = new Rectangle(23, 82, 66, 20);
        public Digit(int n)
            super();
            rect[0] = topRectangle;
            rect[1] = leftTopRectangle;
            rect[2] = midRectangle;
            rect[3] = leftBottomRectangle;
            rect[4] = bottomRectangle;
            rect[5] = rightTopRectangle;
            rect[6] = rightBottomRectangle;
            for (int i = 0; i<7; i++)
                add(rect);
    setVisible(true);
    public void HideDigit(){
    for (int i = 0; i<7; i++)
    rect[i].setVisible(false);
    void changeColor() {
    if(cindex==3)
    cindex=0;
    for (int i = 0; i < rect.length; i++) {
    rect[i].setBackground(mycolor[cindex]);
    //o1[i].setBackground(mycolor[cindex]);
    cindex++;
    void DisplayNumber(int n, int decimals)
    n=increment;
    switch(increment)
    case 0:
    displayzero();
    break;
    case 1:
    displayone();
    break;
    case 2:
    displaytwo();
    break;
    case 3:
    displaythree();
    break;
    case 4:
    displayfour();
    break;
    case 5:
    displayfive();
    break;
    case 6:
    displaysix();
    break;
    case 7:
    displayseven();
    break;
    case 8:
    displayeight();
    break;
    case 9:
    displaynine();
    break;
    public void SetDecimal(boolean flag)
    decimal = flag;
    o1.setVisible(decimal);
    // void incDown() {
    // if(increment==0)
    // increment=10;
    // increment--;
    // switch(increment)
    // case 0:
    // displayzero();
    // break;
    // case 1:
    // displayone();
    // break;
    // case 2:
    // displaytwo();
    // break;
    // case 3:
    // displaythree();
    // break;
    // case 4:
    // displayfour();
    // break;
    // case 5:
    // displayfive();
    // break;
    // case 6:
    // displaysix();
    // break;
    // case 7:
    // displayseven();
    // break;
    // case 8:
    // displayeight();
    // break;
    // case 9:
    // displaynine();
    // break;
    void incUp() {
    System.exit(WIDTH);
    // if(increment==9)
    // increment=-1;
    // increment++;
    // switch(increment)
    // case 0:
    // displayzero();
    // break;
    // case 1:
    // displayone();
    // break;
    // case 2:
    // displaytwo();
    // break;
    // case 3:
    // displaythree();
    // break;
    // case 4:
    // displayfour();
    // break;
    // case 5:
    // displayfive();
    // break;
    // case 6:
    // displaysix();
    // break;
    // case 7:
    // displayseven();
    // break;
    // case 8:
    // displayeight();
    // break;
    // case 9:
    // displaynine();
    // break;
    void displayzero()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(false);
    leftBottomRectangle.setVisible(true);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displayone()
    topRectangle.setVisible(false);
    leftTopRectangle.setVisible(false);
    midRectangle.setVisible(false);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(false);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displaytwo()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(false);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(true);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(false);
    void displaythree()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(false);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displayfour()
    topRectangle.setVisible(false);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(false);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displayfive()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(false);
    rightBottomRectangle.setVisible(true);
    void displaysix()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(true);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(false);
    rightBottomRectangle.setVisible(true);
    void displayseven()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(false);
    midRectangle.setVisible(false);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(false);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displayeight()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(true);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    void displaynine()
    topRectangle.setVisible(true);
    leftTopRectangle.setVisible(true);
    midRectangle.setVisible(true);
    leftBottomRectangle.setVisible(false);
    bottomRectangle.setVisible(true);
    rightTopRectangle.setVisible(true);
    rightBottomRectangle.setVisible(true);
    package led7segment;
    import javax.swing.*;
    import java.awt.*;
    /** Oval Supplier Class
    * Robert Lundahl
    * cs1410-002
    * @author Matthew Lohmeyer
    public class Oval extends JComponent {
    private Color mycolor[] = new Color[]{Color.RED, Color.GREEN,  Color.BLUE};
    private int cindex = 0;
    Oval o1[] = new Oval[0];
    /** post: getX() == x and getY() == y
    * and getWidth() == w and getHeight() == h
    * and getBackground() == Color.black
         public Oval(int x, int y, int w, int h) {
    super();
    setBounds(x, y, w, h);
    setBackground(Color.black);
    /** post: this method draws a filled Oval
    * and the upper left corner of the bounding rectangle is (getX(), getY())
    * and the oval's dimensions are getWidth() and getHeight()
    * and the oval's color is getBackground()
    @Override
    public void paint(Graphics g) {
    g.setColor( getBackground() );
    g.fillOval(0, 0, getWidth()-1, getHeight()-1);
    paintChildren(g);
    void changeColor() {
    if(cindex==3)
    cindex=0;
    for (int i = 0; i < o1.length; i++) {
    //rect[i].setBackground(mycolor[cindex]);
    o1[i].setBackground(mycolor[cindex]);
    cindex++;
    package led7segment;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.*;
    import javax.swing.*;
    * Robert Lundahl
    * cs1410-002
    * @author Matthew Lohmeyer
    public class Rectangle extends JComponent
    public Rectangle(int x, int y, int w, int h) {
    super();
         setBounds(x, y, w, h);
    setBackground(Color.black);
    @Override
    public void paint(Graphics g) {
    g.setColor( getBackground() );
    g.fillRect(0, 0, getWidth()-1, getHeight()-1);
    paintChildren(g);
    Edited by: matttheskibum7 on Feb 9, 2008 8:22 PM
    Edited by: matttheskibum7 on Feb 9, 2008 8:27 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Your code does not compile.
    EDIT:
    for instance your Main class alone has a several glaring problems that suggest that you are foundering here. Please see comments in code below:
    public class Main {
        public static void main(String[] args) throws InterruptedException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            MyJFrame mjf = new MyJFrame();
            // why use "while (true)"??? Swing is supposed to be event driven and doesn't need loops like this.
            // do you need to use a Swing Timer instead?
            while (true) {
                int deci = (int)(Math.random() * 3);
                int num = (int)(Math.random() * 1000);
                // why is the method below being called as if it were a
                // static method when it's not?  This is not a legal
                // expression
                Digit.DisplayNumber(num, deci);
                // why is the method below putting the event dispatch thread
                // (the EDT) to sleep.  While this is legal, it's not a smart
                // thing to do
                Thread.sleep(4000);
    }Edited by: Encephalopathic on Feb 9, 2008 10:15 PM

  • Help with implementing two different programs

    I need help with a couple of Java programs that I downloaded. I hope someone can help me. They work great if they're on their own, but if they are both on the same page, the 2nd one works, and the 1st one stops working. I'm pretty new to Java, so I don't know how to debug it too well.. Here's the 1st program:
    Conveyor belt slideshow script-
    ? Dynamic Drive (www.dynamicdrive.com)
    For full source code, 100's more DHTML scripts, and Terms Of Use, visit dynamicdrive.com
    //Specify the slider's width (in pixels)
    var sliderwidth="250px"
    //Specify the slider's height
    var sliderheight="19px"
    //Specify the slider's slide speed (larger is faster 1-10)
    var slidespeed=2
    //configure background color:
    slidebgcolor=""
    //Specify the slider's images
    var leftrightslide=new Array()
    var finalslide=''
    leftrightslide[0]='<img src="images/movingwords.gif">'
    ////NO NEED TO EDIT BELOW THIS LINE////////////
    var copyspeed=slidespeed
    leftrightslide='<nobr>'+leftrightslide.join(" ")+'</nobr>'
    var iedom=document.all||document.getElementById
    if (iedom)
    //Next line edited for readability
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">
    '+leftrightslide+'</span>')
    var actualwidth=''
    var cross_slide, ns_slide
    function fillup(){
    if (iedom){
    cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
    cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
    cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
    actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth
    cross_slide2.style.left=actualwidth+20+"px"
    else if (document.layers){
    ns_slide=document.ns_slidemenu.document.ns_slidemenu2
    ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
    ns_slide.document.write(leftrightslide)
    ns_slide.document.close()
    actualwidth=ns_slide.document.width
    ns_slide2.left=actualwidth+20
    ns_slide2.document.write(leftrightslide)
    ns_slide2.document.close()
    lefttime=setInterval("slideleft()",30)
    window.onload=fillup
    function slideleft(){
    if (iedom){
    if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
    cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
    else
    cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+30+"px"
    if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
    cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
    else
    cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+30+"px"
    else if (document.layers){
    if (ns_slide.left>(actualwidth*(-1)+8))
    ns_slide.left-=copyspeed
    else
    ns_slide.left=ns_slide2.left+actualwidth+30
    if (ns_slide2.left>(actualwidth*(-1)+8))
    ns_slide2.left-=copyspeed
    else
    ns_slide2.left=ns_slide.left+actualwidth+30
    if (iedom||document.layers){
    with (document){
    document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
    if (iedom){
    write('<div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden">')
    //Next line edited for readability
    write('<div style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';
    background-color:'+slidebgcolor+'" onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
    write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
    write('<div id="test3" style="position:absolute;left:-1000px;top:0px"></div>')
    write('</div></div>')
    else if (document.layers){
    write('<ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'>')
    write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
    write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
    write('</ilayer>')
    document.write('</td></table>')
    }Here's the 2nd program:
    //Fade-in image slideshow- By Dynamic Drive
    //For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
    //This credit MUST stay intact for use
    var slideshow_width='305px' //SET IMAGE WIDTH
    var slideshow_height='152px' //SET IMAGE HEIGHT
    var pause=5000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
    var fadeimages=new Array()
    //SET IMAGE PATHS. Extend or contract array as needed
    fadeimages[0]="images/Computer Retail Store.jpg"
    fadeimages[1]="images/Computer S&S ad.jpg"
    fadeimages[2]="images/Computer S&S ad 2.jpg"
    fadeimages[3]="images/Phone S&S ad.jpg"
    ////NO need to edit beyond here/////////////
    var preloadedimages=new Array()
    for (p=0;p<fadeimages.length;p++){
    preloadedimages[p]=new Image()
    preloadedimages[p].src=fadeimages[p]
    var ie4=document.all
    var dom=document.getElementById
    if (ie4||dom)
    //Next line edited for readability
    document.write('<div style="position:relative;width:'+slideshow_width+';height:'+slideshow_height+';overflow:hidden">
    <div  id="canvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:
    alpha(opacity=10);-moz-opacity:10"></div><div id="canvas1" style="position:absolute;width:'+slideshow_width+';
    height:'+slideshow_height+';top:0;left:0;filter:
    alpha(opacity=10);-moz-opacity:10"></div></div>')
    else
    document.write('<img name="defaultslide" src="'+fadeimages[0]+'">')
    var curpos=10
    var degree=10
    var curcanvas="canvas0"
    var curimageindex=0
    var nextimageindex=1
    function fadepic(){
    if (curpos<100){
    curpos+=10
    if (tempobj.filters)
    tempobj.filters.alpha.opacity=curpos
    else if (tempobj.style.MozOpacity)
    tempobj.style.MozOpacity=curpos/100
    else{
    clearInterval(dropslide)
    nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1"
    tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
    tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">'
    nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0
    setTimeout("rotateimage()",pause)
    function rotateimage(){
    if (ie4||dom){
    resetit(curcanvas)
    var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
    crossobj.style.zIndex++
    var temp='setInterval("fadepic()",50)'
    dropslide=eval(temp)
    curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0"
    else
    document.images.defaultslide.src=fadeimages[curimageindex]
    curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0
    function resetit(what){
    curpos=10
    var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
    if (crossobj.filters)
    crossobj.filters.alpha.opacity=curpos
    else if (crossobj.style.MozOpacity)
    crossobj.style.MozOpacity=curpos/100
    function startit(){
    var crossobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
    crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">'
    rotateimage()
    if (ie4||dom)
    window.onload=startit
    else
    setInterval("rotateimage()",pause)Like I said, if the 2nd program is put the same page with the 1st, the 1st program stops working. Any ideas? I would really like to implement both of these programs.

    The code you post is javascript, NOT java ! ... but either way, maybe the scripts have variables in conflict, so if you pack each piece of code in diferent functions and then you call the functions it may work.

  • Help with GMAIL in Mail Program....

    Hi,
    I am using the Apple Mail Program in Leopard and just picked up a Gmail account. I want to set up my Gmail account on 4 different computers work/home/laptop) that I access all the time and am hoping I can set it up so that wherever I check my mail it looks more or less like it does on Gmail.com with respect to the emails:
    1. All mail that I've deleted on another computer is gone from all the other computers when checking mail on those other computers. Is that possible??? Currently, I use a bellsouth.net account and a .mac account, and when I log on to any of the computers via the mail program, it gives me all of my 'new mail', whether or not it was deleted on another computer.
    2. Sent mail. Is there any way to send it on one computer's Mail program and have it show up in my Sent box on the other computers?
    3. Ditto on Trash and other folders
    I did try to set it up my Gmail account using IMAP but I thendeleted the account on Mail because it looked 'weird'. I had a Mailbox in my Inbox for the Gmail account and then also another whole separate, duplicate Gmail account (with All Mail, Drafts, Sent Mail, Spam, Starred, and Trash Folders) further down the left side of mail. In testing an email to gmail account from my .mac account, the mail ended up in two places in my Mail and deleting one did not delete the others.
    If this cannot work, I can just go to gmail.com. BUT, I so love MAIL that I am hoping there is a fix to all this.
    Thanks in advance for any help you can provide.

    My recollection is that unless you are a paid Hotmail account member, you cannot use Mail. Do a search within the discussion group, as I am not an expert, but I recall not getting Hotmail for that very reason.
    Perhaps give gmail a try.....
    That said....I still need some help with my posting! So please and thank you.

  • Help with RMI university assignment

    Hi everybody,
    The assignment asks for the definition of three remote interfaces ICompany, IProject and IStaff, define one 1:M relationship (ICompany -> IProject) and print on the console the company together with the projects they have placed. There is no requirement for a DB therefore i've create a method on the server
    populateDummyDB(ProjectImpl proj)that fills a Vector with projects with their coresponding company ID's.
    I've also created a company instance on the server which i successfully print on the client by callingprintCompany(Object obj) but i need help with theprintProjects() so that as soon the company is printed it searches the Vector for projects that have the same companyID matches the PK with the FK and print those projects.
    Any help will be more than welcome.
    Regards,
    Nick Paicopoulos
    BSc Applied Computing.

    Thanks for the reply and sorry for the vagueness.
    The company is created and bound to RMI on the Server
    CompanyImpl myCom = new CompanyImpl("101234", "WH Smith",
                        "Nick Parks", null);
    myCom.bindToRMI("com1"); also on the Server the Vector that is defined in the ProjectImpl.java is populated
    public static void populateDummyDB(ProjectImpl proj)
                throws RemoteException {
            proj.addProject(new ProjectImpl("Project A", "10 Feb 2005", 11000,
                    "101234", null, null));
            proj.addProject(new ProjectImpl("Project B", "16 Feb 2005", 8700,
                    "178745", null, null));
            proj.addProject(new ProjectImpl("Project C", "19 Feb 2005", 17400,
                    "130928", null, null));
            proj.addProject(new ProjectImpl("Project D", "27 Feb 2005", 12800,
                    "178745", null, null));
            proj.addProject(new ProjectImpl("Project E", "04 Mar 2005", 9760,
                    "101234", null, null));
            proj.addProject(new ProjectImpl("Project F", "09 Mar 2005", 5340,
                    "178745", null, null));
            proj.addProject(new ProjectImpl("Project G", "13 Mar 2005", 15290,
                    "101234", null, null));
            proj.addProject(new ProjectImpl("Project H", "17 Mar 2005", 5780,
                    "101234", null, null));
            proj.addProject(new ProjectImpl("Project I", "23 Mar 2005", 20100,
                    "130928", null, null));
            proj.addProject(new ProjectImpl("Project J", "30 Mar 2005", 6780,
                    "130928", null, null));
    } The company is printed successfully on the Client
    public class HKClientView{
        public static void main(String[] args) {
            HKClientView cmdUI = new HKClientView();
        public static final String SERVER_NAME = "localhost";
        public HKClientView() {
            ICompany yourCom = getRemoteCompany();
            try {
                CompanyTO yourComData = yourCom.getCompanyData();
                printCompany(yourComData);
    //            printProjects();
            } catch (RemoteException re) {
                System.out.println("Exception thrown while creating company "
                        + "instance! " + re);
        private ICompany getRemoteCompany() {
            ICompany myCompany = null;
            ProjectImpl myProject = null;
            try {
                myCompany = (ICompany) Naming.lookup("//" + SERVER_NAME + "/com1");
            } catch (Exception e) {
                System.out.println("Exception thrown while creating company "
                        + "instance! " + e);
            return myCompany;
        private void printCompany(Object obj) {
            System.out.println(obj.toString());
    } If you look closely at my dummy DB table four out of the ten projects belong to the company that i've created since the have common companyID = "101234". How can i get those projects printed on the Client?
    Regards,
    Nick Paicopoulos.

  • Help with Sum using FormCalc in Livecycle

    Hello. I'm stuck. I've been doing searches, readings, and all that on how to sum up certain cells in Livecycle. I have tried examples and tutorials and I get stuck when the application says "Error: Accessor ' ' Unknown".
    I'm such a novice in using Livecycle and I'm not a programmer. So, if someone can help me on why it does this, that would be awesome!

    Here you go.  I rename it.  Couple of things.  Too many subforms (unless you intend to do something else with this).  Also, make sure you save your forms as "dynamic" if you intend to have user enter info.  I couldn't tell if you were importing/exporting to a spreadsheet.  Note the formcalc.  Your fields need to be named the same.  In my example they are: ExpCosts.
    I'm not very good with the formcalc/java and variables but am more than willing to help with what I can

  • Help with Rock, Paper, Scissors Program

    I need some help with my program, I got understand writing each of the methods I have to do but then i don't understand how to piece it together to make the program work. in the main method...I didn't complete the scrolling message method I just wanted to get the game itself working first then I was going to complete that method. I just need to know if I'm heading in the right direction or if i did something completly wrong
    import javax.swing.*;
    public class RockPaperScissors
         public static void displayScrollingMessage (String list)
              String header = "Game #\tUser\tComputer\tWinner\t";
         public static void getUserChoice ( )
              int game = 1;
              for ( game = 1; game > 0 ; game ++)
                   String input = JOptionPane.showInputDialog ("Choose Rock, Paper, or Scissors\n Enter\n 1 for Rock" +
                                                                                              "\n2 for Paper\n3 for Scissors\n4 to Exit");
                   String list = "   ";
                   int option = Interger.parseInt (input);
                   switch (option)
                        case 1:
                                  int userChoice = 1;
                                  getComputersChoice ();
                                  itemName (userChoice);
                                  itemName2 (computersChoice);
                                  whowins (userChoice, computersChoice);
                                  winnerName (winner);
                                  winlose (winner);
                                  String list =+ game + "/t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
                                  String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
                                                                                                                  + itemName2 + "\nTherefore " + winlose);
                                  return userChoice;
                                  break;
                        case 2:
                                  userChoice = 2;
                                  getComputersChoice ();
                                  itemName (userChoice);
                                  itemName2 (computersChoice);
                                  whowins (userChoice, computersChoice);
                                  winnerName (winner);
                                  winlose (winner);
                                  String list =+ game + "\t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
                                  String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
                                                                                                                  + itemName2 + "\nTherefore " + winlose);
                                  return userChoice;
                                  break;
                        case 3:
                                  userChoice = 3;
                                  getComputersChoice ();
                                  itemName (userChoice);
                                  itemName2 (computersChoice);
                                  whowins (userChoice, computersChoice);
                                  winnerName (winner);
                                  winlose (winner);
                                  String list =+ game + "\t" + itemName + "\t" + itemName2 + "\t" + winnerName + "\n";
                                  String winner = JOptionPane.showOutputDialog (null, "You picked " + itemName + " and the computer picked "
                                                                                                                  + itemName2 + "\nTherefore " + winlose);                              
                                  return userChoice;
                                  break;
                        case 4:
                                  break;
                        default:
                             JOptionPane.showMessageDialog (null, "Error!! Please enter a valid option!"
                                                                                              , JOptionPane.WARNING_MESSAGE);
                        break;
         public static int getComputersChoice ()
              int computersChoice = (int) (3 * Math.random() + 1);
              return computersChoice;
         public static String itemName (int userChoice)
              if (userChoice == 1)
                   String itemName = Rock;
              else
                   if (userChoice == 2)
                        String itemName = Paper;
                   else
                        if (userChoice == 3)
                             String itemName = Scissors;
              return itemName;
              public static string itemName2 (int computersChoice)
              if (computersChoice == 1)
                   String itemName2 = Rock;
              else
                   if (computersChoice == 2)
                        String itemName2 = Paper;
                   else
                        if (computersChoice == 3)
                             String itemName2 = Scissors;
              return itemName2;
         public static string winlose (int winner)
              if (winner == 1)
                   winlose = "You Win!!!";
              else
              if (winner == 2)
                   winlose = "You Lose!!";
              else
              if (winner == 3)
                   winlose = "Its a Tie!!";
         return winlose;
         public static string winnerName (int winner)
              if (winner == 1)
                   String winnerName = "User";
              else
              if (winner == 2)
                   String winnerName = "Computer";
              else
              if (winner == 2)
                   String winnerName = "Tie";
              return winnerName;
         public static void whoWins (int computersChoice, int userChoice)
              if (userChoice == 1 && computersChoice == 1)
                   int winner = 3;
              else
              if (userChoice == 1 && computersChoice == 2)
                   int winner = 2;
              else
              if (userChoice == 1 && computersChoice == 3)
                   int winner = 1;
              else
              if (userChoice == 2 && computersChoice == 1)
                   int winner = 1;
              else
              if (userChoice == 2 && computersChoice == 2)
                   int winner = 3;
              else
              if (userChoice == 2 && computersChoice == 3)
                   int winner = 2;
              else
              if (userChoice == 3 && computersChoice == 1)
                   int winner = 2;
              else {
              if (userChoice == 3 && computersChoice == 2)
                   int winner = 1;
              else
              if (userChoice == 3 && computersChoice == 3)
                   int winner = 3;
              return winner;
         public static void main (String args [])
              getUserChoice ( );
              System.exit (0);
    }

    Here's something to compare to
    import javax.swing.*;
    public class RockPaperScissors
      public RockPaperScissors()
        String[] pick = {"Rock","Paper","Scissors","Exit"};
        int user = 0, computer = 0;
        String result = "", output = "";
        while(user < 3)
          user = JOptionPane.showOptionDialog(null,"Which do you want?",
                               "Rock-Paper-Scissors",-1,-1,null,pick,"");
          if(user == 3) break;
          computer = (int)(3*Math.random());
          result = getWinner(user,computer);
          output = "You chose "+pick[user] + "\nComputer chose " + pick[computer]+
                   "\n\nResult:- " + result;
          JOptionPane.showMessageDialog(null,output);        
        System.exit(0);
      public String getWinner(int player, int comp)
        if(Math.abs(player - comp) > 1)
          if(player == 2) player = -1;
          if(comp == 2) comp = -1;
        return player > comp? "You win.":player < comp? "Computer wins.":"Tie.";
      public static void main(String[] args){new RockPaperScissors();}
    }

  • I need help with the Bon Scott program

    Help me! I am learning Java from the book, "Teach Yourself Java through Osmosis" and I am having trouble with the Bon Scott program. Everytime I run it, which has been ca. 2 billion, it prints out, "Some balls are held for charity and some for fancy dress, but when they're held for pleasure, they're the balls that I like the best." It then proceeds to get pissed and finally vomits.
    Any suggestions ?

    What color is the vomit? That is, exactly what does it do when it gets pissed and vomits?

  • Need help with session using dreamweaver

    have created a login page (php/mysql) with username and
    password boxes. when the form is submitted the mainpage loads up.
    i want the main page to be specific to that user, so i want
    their name to appear in the first line. eg.. Welcome back 'David'
    I read a tutorial in the past that tought me to send the
    users id in the URL and then create a record set on the mainpage
    that was filtered by the URL parameter.
    I have forgotten how to do this and the tutorial is no longer
    available on Adobe's site.
    I tried that with
    $_SESSION['MM_Username'] = $loginUsername; \\ in first page
    then
    echo $_SESSION["MM_username"]; \\in second page, but the
    problem is that is not showing user name.
    i need help with that please!
    can anyone tell me how to do this? Thanks in advance,
    AM

    IN the second page, you have to make sure that the session
    has been started.
    Put this at the very top of the page -
    <?php if (!isset($_SESSION)) session_start(); ?>
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Alidad" <[email protected]> wrote in
    message
    news:g184i4$jgf$[email protected]..
    > have created a login page (php/mysql) with username and
    password boxes.
    > when
    > the form is submitted the mainpage loads up.
    >
    > i want the main page to be specific to that user, so i
    want their name to
    > appear in the first line. eg.. Welcome back 'David'
    >
    > I read a tutorial in the past that tought me to send the
    users id in the
    > URL
    > and then create a record set on the mainpage that was
    filtered by the URL
    > parameter.
    >
    > I have forgotten how to do this and the tutorial is no
    longer available on
    > Adobe's site.
    >
    > I tried that with
    > $_SESSION['MM_Username'] = $loginUsername; \\ in first
    page then
    > echo $_SESSION["MM_username"]; \\in second page, but
    > the
    > problem is that is not showing user name.
    >
    > i need help with that please!
    >
    > can anyone tell me how to do this? Thanks in advance,
    >
    > AM
    >

  • Need urgent help with a new Z program please

    I have to write a program that finds files matching some pattern, for example I have files test1,test2,test3 in a directory then if I pass test* as parameter it should find all the files i.e, test1,2,3. I have to then store the files in internal table, loop through it and have to call some other program zzz that has a selection screen with default parameters.
    1) Is there any function that I can call that gives all the files by passing wild card (ex:test*) and store the files in internal table?
    2) How do I call some other program ZZZ from my program?
    3) How do I pass values from my program to other program's selection screen?
    Your help would be greatly appreciated.
    Thanks.
    Mithun

    Hi,
    1) data: FILE_TABLE TYPE STANDARD TABLE OF FILE_INFO.
    data: wa_file type file_info.
    data: count type i.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES
                EXPORTING
                    DIRECTORY = 'C:\'
                    FILTER    = 'test.*'
                    files_only = 'X'
                changing
                    FILE_TABLE = file_table[]
                    count      = count.
    loop at file_table into wa_file.
      write: / wa_file-filename.
    endloop.
    2) You can use SUBMIT statement to call another program..
    3) In the SUBMIT statement you can use the WITH addition to pass the values to the program.
    Thanks,
    Naren

Maybe you are looking for