Help with program plz (long code)

anyone know how i can fix these 2 errors:
Driver2.java:47: code is already defined in main(java.lang.String[])
String code = JOptionPane.showInputDialog(
^
Driver2.java:51: incompatible types
found : java.lang.String
required: int
int val = bc.getCode();
^
the case 2 in the driver is where it messes up, i believe..it works with just the case 1...any help/advice is appreciated(i am aware of spacing errors)
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Driver2
   public static void main(String[] args)
      String userChoice;
      int choice;
Scanner keyboard = new Scanner(System.in);
userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
+ "Enter 2 to enter a bar code:\n"
+ "Enter 3 to exit program:\n");
choice = Integer.parseInt(userChoice);
while (choice != 3)
       switch (choice)
       case 1:
       String input = JOptionPane.showInputDialog( "Please enter a five-digit zip code: ");
int num = Integer.parseInt(input);
BarCode bc = new BarCode(num);
String code = bc.getCode();
JOptionPane.showMessageDialog(null, "The barcode of the zip is: " + code);
System.exit(0);
break;
case 2:
String code = JOptionPane.showInputDialog( "Please enter bar code: ");
int val = bc.getCode();
if (val >= 0)
System.out.println("The zip code is: " + val);
else
System.out.println("Incorrect bar code data");
System.exit(0);
break;
case 3:
break;
userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
+ "Enter 2 to enter a bar code:\n"
+ "Enter 3 to exit program:\n");
   public BarCode(int n)
      zip = n;
   public String getCode()
      String barCode = "|";
      int sum = 0;
      int temp = 0;
      temp = zip / 10000;
      sum = sum + temp;
      Digit d1 = new Digit(temp);
      barCode = barCode + d1.getCode();
      zip = zip % 10000;
      temp = zip / 1000;
      sum = sum + temp;
      Digit d2 = new Digit(temp);
      barCode = barCode + d2.getCode();
      zip = zip % 1000;
      temp = zip / 100;
      sum = sum + temp;
      Digit d3 = new Digit(temp);
      barCode = barCode + d3.getCode();
      zip = zip % 100;
      temp = zip / 10;
      sum = sum + temp;
      Digit d4 = new Digit(temp);
      barCode = barCode + d4.getCode();
      zip = zip % 10;
      temp = zip;
      sum = sum + temp;
      Digit d5 = new Digit(temp);
      barCode = barCode + d5.getCode();
      temp = 10 - (sum % 10);
      Digit d6 = new Digit(temp);
      barCode = barCode + d6.getCode() + "|";
      return barCode;
   private int zip;
public class BarCode1
   public BarCode1(int n)
      zip = n;
   public String getCode()
      String barCode = "|";
      int sum = 0;
      int temp = 0;
      temp = zip / 10000;
      sum = sum + temp;
      Digit d1 = new Digit(temp);
      barCode = barCode + d1.getCode();
      zip = zip % 10000;
      temp = zip / 1000;
      sum = sum + temp;
      Digit d2 = new Digit(temp);
      barCode = barCode + d2.getCode();
      zip = zip % 1000;
      temp = zip / 100;
      sum = sum + temp;
      Digit d3 = new Digit(temp);
      barCode = barCode + d3.getCode();
      zip = zip % 100;
      temp = zip / 10;
      sum = sum + temp;
      Digit d4 = new Digit(temp);
      barCode = barCode + d4.getCode();
      zip = zip % 10;
      temp = zip;
      sum = sum + temp;
      Digit d5 = new Digit(temp);
      barCode = barCode + d5.getCode();
      temp = 10 - (sum % 10);
      Digit d6 = new Digit(temp);
      barCode = barCode + d6.getCode() + "|";
      return barCode;
   private int zip;
public class Digit
   public Digit(int n)
      zip = n;
   public String getCode()
      String bar = "";
      if (zip == 1)
         bar = ":::||";
      else if (zip == 2)
         bar = "::|:|";
      else if (zip == 3)
         bar = "::||:";
      else if (zip == 4)
         bar = ":|::|";
      else if (zip == 5)
         bar = ":|:|:";
      else if (zip == 6)
         bar = ":||::";
      else if (zip == 7)
         bar = "|:::|";
      else if (zip == 8)
         bar = "|::|:";
      else if (zip == 9)
         bar = "|:|::";
      else
         bar = "||:::";
      return bar;
   private int zip;
public class Digit1
   public Digit1(int n)
      zip = n;
   public String getCode()
      String bar = "";
      if (zip == 1)
         bar = ":::||";
      else if (zip == 2)
         bar = "::|:|";
      else if (zip == 3)
         bar = "::||:";
      else if (zip == 4)
         bar = ":|::|";
      else if (zip == 5)
         bar = ":|:|:";
      else if (zip == 6)
         bar = ":||::";
      else if (zip == 7)
         bar = "|:::|";
      else if (zip == 8)
         bar = "|::|:";
      else if (zip == 9)
         bar = "|:|::";
      else
         bar = "||:::";
      return bar;
   private int zip;
}

> i got it to compile now...i can toy around w/
it..thanks for the help
Good.
Stick with this handle, ok?I must say I am not thrilled with
a) when I questioned the first post of WhiteSox asking if it was bugz or a classmate or what I was ignored by the OP
b) I guess the OP is trying to distance himself from his very first thread where somebody did part of his homework for him with results that are now plainly evident. As I predicted at the end of the last thread.
http://forum.java.sun.com/thread.jspa?threadID=703258 Reply 11
I hope that matsabigman and others who help homework posters by doing it for them will take note of the results of this help thus far. Not much good has come of this.
BigMan/WhiteSox I am still detecting a fundamental lack of basic concepts on your part. This is the underlying cause of your compile errors but those are only a symptom. You can continue treating the symptoms but it would be a better use of your time to treat the disease, which in this case means spending some time getting a better grasp of Java fundamentals.

Similar Messages

  • Search help with programming

    Hai,
    Can any one give example for search help with Programming?
    I hope we can create search help with help of coding.
    With Regards,Jaheer.

    yes u can create search help by using match code in programs
    for eq
    go with abap editor se 38
    provide the name of program
    parameters : vendor like lfa1-lifnr matchcode object yzob.
    double click on yzob
    provide description for search help
    provide selection method
    provide search help parameter
    enable check box for import and export
    provide lpos
               spos
    save check activate
    press f4 for check and import values i.e it will display a records list available in database table
    rewards points please

  • Help With Program Please

    Hi everybody,
    I designed a calculator, and I need help with the rest of the scientific actions. I know I need to use the different Math methods, but what exactly? Also, it needs to work as an applet and application, and in the applet, the buttons don't appear in order, how can I fix that?
    I will really appreciate your help with this program, I need to finish it ASAP. Please e-mail me at [email protected].
    Below is the code for the calcualtor.
    Thanks in advance,
    -Maria
    // calculator
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class calculator extends JApplet implements
    ActionListener
    private JButton one, two, three, four, five, six, seven,
    eight, nine, zero, dec, eq, plus, minus, mult, div, clear,
    mem, mrc, sin, cos, tan, asin, acos, atan, x2, sqrt, exp, pi, percent;
    private JLabel output, blank;
    private Container container;
    private String operation;
    private double number1, number2, result;
    private boolean clear = false;
    //GUI
    public void init()
    container = getContentPane();
    //Title
    //super("Calculator");
    JPanel container = new JPanel();     
    container.setLayout( new FlowLayout( FlowLayout.CENTER
    output = new JLabel("");     
    output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
    output.setPreferredSize(new Dimension(1,26));     
    getContentPane().setBackground(Color.white);     
    getContentPane().add( "North",output );     
    getContentPane().add( "Center",container );
    //blank
    blank = new JLabel( " " );
    container.add( blank );
    //clear
    clear = new JButton( "CE" );
    clear.addActionListener(this);
    container.add( clear );
    //seven
    seven = new JButton( "7" );
    seven.addActionListener(this);
    container.add( seven );
    //eight
    eight = new JButton( "8" );
    eight.addActionListener(this);
    container.add( eight );
    //nine
    nine = new JButton( "9" );
    nine.addActionListener(this);
    container.add( nine );
    //div
    div = new JButton( "/" );
    div.addActionListener(this);
    container.add( div );
    //four
    four = new JButton( "4" );
    four.addActionListener(this);
    container.add( four );
    //five
    five = new JButton( "5" );
    five.addActionListener(this);
    container.add( five );
    //six
    six = new JButton( "6" );
    six.addActionListener(this);
    container.add( six );
    //mult
    mult = new JButton( "*" );
    mult.addActionListener(this);
    container.add( mult );
    //one
    one = new JButton( "1" );
    one.addActionListener(this);
    container.add( one );
    //two
    two = new JButton( "2" );
    two.addActionListener(this);
    container.add( two );
    //three
    three = new JButton( "3" );
    three.addActionListener(this);
    container.add( three );
    //minus
    minus = new JButton( "-" );
    minus.addActionListener(this);
    container.add( minus );
    //zero
    zero = new JButton( "0" );
    zero.addActionListener(this);
    container.add( zero );
    //dec
    dec = new JButton( "." );
    dec.addActionListener(this);
    container.add( dec );
    //plus
    plus = new JButton( "+" );
    plus.addActionListener(this);
    container.add( plus );
    //mem
    mem = new JButton( "MEM" );
    mem.addActionListener(this);
    container.add( mem );
    //mrc
    mrc = new JButton( "MRC" );
    mrc.addActionListener(this);
    container.add( mrc );
    //sin
    sin = new JButton( "SIN" );
    sin.addActionListener(this);
    container.add( sin );
    //cos
    cos = new JButton( "COS" );
    cos.addActionListener(this);
    container.add( cos );
    //tan
    tan = new JButton( "TAN" );
    tan.addActionListener(this);
    container.add( tan );
    //asin
    asin = new JButton( "ASIN" );
    asin.addActionListener(this);
    container.add( asin );
    //acos
    acos = new JButton( "ACOS" );
    cos.addActionListener(this);
    container.add( cos );
    //atan
    atan = new JButton( "ATAN" );
    atan.addActionListener(this);
    container.add( atan );
    //x2
    x2 = new JButton( "X2" );
    x2.addActionListener(this);
    container.add( x2 );
    //sqrt
    sqrt = new JButton( "SQRT" );
    sqrt.addActionListener(this);
    container.add( sqrt );
    //exp
    exp = new JButton( "EXP" );
    exp.addActionListener(this);
    container.add( exp );
    //pi
    pi = new JButton( "PI" );
    pi.addActionListener(this);
    container.add( pi );
    //percent
    percent = new JButton( "%" );
    percent.addActionListener(this);
    container.add( percent );
    //eq
    eq = new JButton( "=" );
    eq.addActionListener(this);
    container.add( eq );
    //Set size and visible
    setSize( 190, 285 );
    setVisible( true );
    public static void main(String args[]){
    //execute applet as application
         //applet's window
         JFrame applicationWindow = new JFrame("calculator");
    applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //applet instance
         calculator appletObject = new calculator();
         //init and start methods
         appletObject.init();
         appletObject.start();
    } // end main
    public void actionPerformed(ActionEvent ae)
    JButton but = ( JButton )ae.getSource();     
    //dec action
    if( but.getText() == "." )
    //if dec is pressed, first check to make shure there
    is not already a decimal
    String temp = output.getText();
    if( temp.indexOf( '.' ) == -1 )
    output.setText( output.getText() + but.getText() );
    //clear action
    else if( but.getText() == "CE" )
    output.setText( "" );
    operation = "";
    number1 = 0.0;
    number2 = 0.0;
    //plus action
    else if( but.getText() == "+" )
    operation = "+";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //minus action
    else if( but.getText() == "-" )
    operation = "-";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //mult action
    else if( but.getText() == "*" )
    operation = "*";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //div action
    else if( but.getText() == "/" )
    operation = "/";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //eq action
    else if( but.getText() == "=" )
    number2 = Double.parseDouble( output.getText() );
    if( operation == "+" )
    result = number1 + number2;
    else if( operation == "-" )
    result = number1 - number2;
    else if( operation == "*" )
    result = number1 * number2;
    else if( operation == "/" )
    result = number1 / number2;
    //output result
    output.setText( String.valueOf( result ) );
    clear = true;
    operation = "";
    //default action
    else
    if( clear == true )
    output.setText( "" );
    clear = false;
    output.setText( output.getText() + but.getText() );

    Multiple post:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=474370&tstart=0&trange=30

  • Query Help with Item Master & Warehouse Code

    Forum,
    I would like help with a query to identify any items within a database where a particular warehouse code does NOT exist against it. At present I have the following:
    select T0.ItemCode, T1.WhsCode from OITM T0
    INNER JOIN OITW T1 on T0.ItemCode = T1.ItemCode
    where T0.ItemCode NOT IN ('WHS1')
    This is returning all other instance and not just a list of item codes where 'WHS1' is missing from within the 'Stock Data' tab.
    Thanks,
    Sarah

    Hi Sarah...
    Try This
    SELECT T0.ItemCode, T0.ItemName, T1.WhsCode
    FROM OITM T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
    WHERE T1.WhsCode not in ( 'WHS1')
    Regards
    Kennedy

  • Help with java digital signing code

    hello people.
    can anybody help me?
    i have find a java code to resolve my problem with sending pay in soap envelope with digital signature and attached certificate. i compiled it with jdk jdk1.6.0_37. and it works.
    i need it to work in built-in jvm in oracle 9i. in oracle 9i jvm release is 1.3.1. Java code does not work there. there is an error
    class import com.sun.org.apache.xerces.internal.impl.dv.util.Base64 not found in import.
    i did not find this class in network.
    can anybody help with rewriting it for jvm 1.3.1?
    thanks in advance.
    code below:
    import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
    import java.io.*;
    import java.security.Key;
    import java.security.KeyStore;
    import java.security.PrivateKey;
    import java.security.Signature;
    import java.security.cert.Certificate;
    public class Sign {
    public static void main(String[] args) throws Exception {
    // TODO code application logic here
    BufferedReader reader = new BufferedReader(new FileReader("c:\\cert.p12"));
    StringBuilder fullText = new StringBuilder();
    String line = reader.readLine();
    while (line != null) {
    fullText.append(line);
    line = reader.readLine();
    KeyStore p12 = KeyStore.getInstance("pkcs12");
    p12.load(new FileInputStream("c:\\cert.p12"), "Hfrtnf$5".toCharArray());
    //????????? ????????? ????, ??? ????? ????? ???????????? alias ? ??????
    //Key key = p12.getKey("my kkb key", "ryba-mech".toCharArray());
    Key key = (Key) p12.getKey("my kkb key", "Hfrtnf$5".toCharArray());
    Certificate userCert = (Certificate) p12.getCertificate("my kkb key");
    String base64Cert = new String(Base64.encode(userCert.getEncoded()));
    //signing
    Signature signer = Signature.getInstance("SHA1withRSA");
    signer.initSign((PrivateKey) key);
    signer.update(fullText.toString().getBytes());
    byte[] digitalSignature = signer.sign();
    String base64sign = new String(Base64.encode(digitalSignature));
    String base64Xml = new String(Base64.encode(fullText.toString().getBytes()));
    System.out.println("<certificate>" + base64Cert+"</certificate>");
    System.out.println("<xmlBody>" + base64Xml+"</xmlBody>");
    System.out.println("<signature>" + base64sign+"</signature>");
    Edited by: user13622283 on 22.01.2013 22:08

    My first search is to see if there is an Apache commons project that provides it. Lo and behold:
    http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
    commons-codec.

  • Can anyone help with programming co ordinates.

    how do i develop a class specification for class points.
    //pointTest.java
    main(...)     
         Point P1;
         P1.create(24,16); // create a point with coordinates {24,16}
         P1.display(); // display the {X,Y} coordinates of P1
    can anyone help with coding to program two points. can anyone elaborate on the stubs shown above to develop one point.

    There's already a Point class. So use that.
    Unless this is a homework in which case, well, it's your homework isn't it? So why are you asking us?

  • Help with some java login code

    hey,
    I am a new member but used to visit the site regularly. I am undergoing a java project and I cannot seem to get my head around how to code when users log in, there name must appear at the top of each page they visit.
    User enters name into a text box. Do I use getter and setter methods? any bit of help would be of some advantage to me.
    Thanks for your time and I'll help with anyone else who is stuck.

    if JSP or servlet use Session...
    if you are using frame you have to consider... which frame is a top parent. that top frame will have the set and get method.. for you to set and retrieve the user name.. bear in mind that different object will have different user...
    so you have to play fair game ...hehehehe :-)

  • Need help with this Pascal Triangle code....

    Hey everyonr i am totally new to Java... so need your help with this code...
    the function makeRows gives me problems... main is correct ... can someone fix my makeRows... i don't see what's wrong
    public class Pascal {
      /** Return ragged array containing the first nRows rows of Pascal's
       *  triangle.
      public static int[][] makeRows(int nRows) {
            int[][] mpr  = new int[nRows+1][];
            int l=0; int r=0;
            for (int row = 0; row < nRows; row++) {
              mpr[row] = new int[row+1];  //index starts at 0
              if (row==0) {
                mpr[0][0]= 1;
                    if (row==1) {
                mpr[1][0]= 1;
                mpr[1][1]= 1;
              if (row>=2) {
                 for (int j = 0; j <= row; j++) {
                    if (j==0)               {l=0;} else {l=mpr[row-1][j-1];}
                    if (j==mpr[row].length-1) {r=0;} else{r=mpr[row-1][j];}
                    mpr[row][j] = l + r;
            return mpr;
      public static void main(String[] args) {
             if (args.length != 1) {
               System.out.println("usage: java " + Pascal.class.getName() + " N_ROWS");
               System.exit(1);
             int nRows = Integer.parseInt(args[0]);
             if (nRows > 0) {
               int[][] pascal = makeRows(nRows);
               for (int[] row : pascal) {
              for (int v : row) System.out.print(v + " ");
              System.out.println("");
         }this makeRows function should return ragged array containing the first nRows rows of Pascal's triangle
    thanks
    Edited by: magic101 on May 9, 2008 4:03 PM

    magic,
    i think corlettk meant that some people might not know what pascal's triangle is.
    also, you didnt say what was wrong with your code, just that it was wrong.
    asking smart questions is about giving as much information you can to get the
    best answer. i would throw a System.out.print between every line of your
    algorithm. i would also supply us with the values you are getting for each row.
    also, this question is asked all the time here. do a forum search.
    1
    11
    121
    1331
    14641

  • HELP WITH AN OLDER VERSION CODE!!!!!

    I am trying to figure out how to convert a code from an older version into JDK1.3.1_01.
    Please HELP!
    Here is my code............
    mport java.awt.*;
    import java.applet.*;
    public class Race extends Applet {
    private Button myButton; //use a button to start the race.
    int race_square; //record the race square 70.
    int t_square; //record the tortoise's position.
    int h_square; //record the hare's position.
    int clock; //record clock ticks.
    public void init()
    myButton=new Button("Start Clock") ; //add button to the top of panel.
    add("North",myButton);
    reset_v();
    public void reset_v()
    race_square=70; // total squares is 70
    t_square=1; //start point =1
    h_square=1; //start point=1
    clock=0; //reset the clock to zero.
    public void race() {
    int i=0; //set some integer varibles.
    int t_random=0; //random number for tortoise.
    int h_random=0; //random number for hare.
    Graphics g=getGraphics(); //define graphics.
    Rectangle r = bounds(); //define painting boundary.
    g.drawString("BANG !!!!!",100,r.height/2-80);
    g.drawString("AND THEY'RE OFF !!!!!",100,r.height/2-70);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the zero clock time.
    do{
    try { Thread.sleep(1000);} //clock ticks 1 second.
    catch (InterruptedException e){}
    clock++;
    g.setColor(Color.lightGray); //clear all the old drawings
    g.fillRect(0,0,r.width,r.height);
    g.setColor(Color.black);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the clock time.
    t_random=getrandom(); // FOR TORTOISE
    if (t_random<=5) t_square+=3; // 50% fast plod: 3 squares to the right.
    else if (t_random>5 && t_random<=7)t_square-=6; // 20% slip: 6 squares to the left.
    else t_square+=1; // 30% slow plod: 1 square to the right.
    h_random=getrandom(); //FOR HARE
    if (h_random<=2) {} // 20% sleep: not move at all.
    else if (h_random>2 && h_random<=4)h_square+=9;// 20% big hop: 9 squares to the right.
    else if (h_random==5) h_square-=12; // 10% big slip: 12 squares to the left.
    else if (h_random>5 && h_random<=8)h_square+=1;// 30% slow hop: 1 square to the right.
    else h_square-=2; // 20% small slip: 2 aquares to the left.
    if(t_square<=0) t_square=1; //always start from 1.
    if(t_square>race_square)t_square=race_square;
    if(h_square<=0) h_square=1; //always start from 1.
    if(h_square>race_square)h_square=race_square;
    g.setColor(Color.red); //draw the tortoise's path: use red color.
    g.fillRect(5,r.height/2-5,5*t_square,5);
    g.drawString("T",5*t_square,r.height/2-7);
    g.setColor(Color.blue); //draw the hare path: use blue color.
    g.fillRect(5,r.height/2+1,5*h_square,5);
    g.drawString("H",5*h_square,r.height/2+17);
    g.setColor(Color.black); //draw the race squares.
    g.drawLine(5,r.height/2,5+5*race_square,r.height/2);
    for(i=5;i<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    if (t_square==h_square &&t_square!=race_square) // tortoise bites the hare.
    g.drawString("OUCH!!!",5+5*h_square,r.height/2-16);
    }while ( t_square=race_square && h_square=race_square && t_square<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    g.drawString("T",5,r.height/2-7); //mark tortoise
    g.drawString("H",5,r.height/2+17); //mark hare
    public int getrandom()
    return( 1+(int)(Math.random()*10)); // generating the random number 1 to 10.
    public boolean action(Event e, Object arg)
    if (e.target instanceof Button)
    reset_v(); //reset the initial variables.
    race(); //use the button the start the race.
    return true;

    You posted this yesterday, at
    http://forum.java.sun.com/thread.jsp?forum=54&thread=185330
    The code you've posted doesn't seem to include Ilikejava's suggested changes - which are, as far as I can tell, the major changes required to bring your applet in line with Java 1.3.
    It will be easier to help if you show what is wrong with your code, if it's generating a compiler error message or throwing an exception.
    Regards,
    -Troy

  • Help with understanding multi-threaded code

    Hi Everyone,
    I am currently reading a book on multi-threading and up until recently I have been able to understand what is going on. The thing is the complexity of the code has just jumped up about two gears without warning. The code is now using inner classes which I am trying to develop an understanding of but I am not finding it easy going, and the book has been lite on explanations. If anybody can help with the following code it will be really appreciated.
    public class SetPriority extends Object
         private static Runnable makeRunnable()
              Runnable r = new Runnable()
                   public void run()
                        for(int i=0; i<5; i++)
                             Thread t = Thread.currentThread();
                             System.out.println("in run() - priority=" + t.getPriority() +
                                          ", name=" + t.getName());
                             try{
                                  Thread.sleep(2000);
                             }catch(InterruptedException x){
                                  //ignore
              return r;
         public static void main(String[] args)
              Thread threadA = new Thread(makeRunnable(), "threadA");
              threadA.setPriority(8);
              threadA.start();
              Thread threadB = new Thread(makeRunnable(), "threadB");
              threadB.setPriority(2);
              threadB.start();
              Runnable r = new Runnable()
                   public void run()
                        Thread threadC = new Thread(makeRunnable(), "threadC");
                        threadC.start();
              Thread threadD = new Thread(r, "threadD");
              threadD.setPriority(7);
              threadD.start();
              try{
                   Thread.sleep(3000);
              }catch(InterruptedException x){
                   //ignore
              threadA.setPriority(3);
              System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority());
    }My greatest challenge is understanding how the makeRunnable() method works. I don't understand how this inner class can be declared static and then multiple "instances" created from it. I know that I have no idea what is going on, please help!!!
    Thanks for your time.
    Regards
    Davo
    P.S.: If you know of any really good references on inner classes, particularly URL resources, please let me know. Thanks again.

    Yikes!! The good news is that you're unlikely to see such convoluted code in real life. But here we go.
    "private static Runnable makeRunnable()" declares a method that returns objects of type Runnable. The fact that the method is declared "static" is pretty irrelevant - I'll describe what that means later.
    The body of the method creates and returns an object of type Runnable. Not much special about it, except that you can give such an object to the constructor of class Thread and as a result the run() method of this Runnable object will be called on a new thread of execution (think - in parallel).
    Now the way it creates this Runnable object is by using the "anonymous inner class" syntax. In effect the method is doing the same as
    public class MyNewClass implements Runnable {
        public void run() {
            // All the same code inside run()
    public class SetPriority {
        private static Runnable makeRunnable() {
            Runnable r = new MyNewClass();
            return r;
        // The rest of the original code
    }Except you don't bother declaring MyNewClass. You're not interested in defining any new method signatures. You just want to create an object that implements Runnable and has certain instructions that you want inside the run() method. Think of the whole approach as shorthand.
    Think about this for a while. In the mean time I'll write up the "static".

  • Elasticity: help with converting Flash 5 code to Flash 8

    Hello
    because I have to make a flash menu with elasticity effect I
    came upon this tutorial:
    http://www.kirupa.com/developer/actionscript/spring.htm
    All OK but the code there works only with Flash 5. I somehow
    managed to concoct code that works for Flash 6 but still I didn't
    come even close to a code working in Flash 8. I'm using
    Actionscript only from version 7, I do not know anything about
    Flash 5 and 6. So please, the more experienced guys, help me!!
    The code I concocted is:
    MovieClip.prototype.move = function (centerx, centery,
    inertia, k) {
    this.x = -this._x+centerx;
    this.y = -this._y+centery;
    this.xp = this.xp*inertia+this.x*k;
    this.yp = this.yp*inertia+this.y*k;
    this._x += this.xp;
    this._y += this.yp;
    onEnterFrame=function() {
    this.move (_root._xmouse,_root._ymouse,0.9,0.1) ;
    This whole code is on the timeline of the MC being moved.
    So now the only thing I need is to make this code work for
    Flash 8
    Please, help

    Just managed to do it !

  • Need a little help with program (long code)

    Jist of program: If User enters a zip code, convert it to bar code. If User enters a bar code, convert it to zip code. Below is the code for the classes. Question is how to get the constructors under the same class to where they can compile. I'm not sure what to do...Any help is definately appreciated
    public class BarCode
       public BarCode(int n)
          zip = n;
       public String getCode()
          String barCode = "|";
          int sum = 0;
          int temp = 0;
          temp = zip / 10000;
          sum = sum + temp;
          Digit d1 = new Digit(temp);
          barCode = barCode + d1.getCode();
          zip = zip % 10000;
          temp = zip / 1000;
          sum = sum + temp;
          Digit d2 = new Digit(temp);
          barCode = barCode + d2.getCode();
          zip = zip % 1000;
          temp = zip / 100;
          sum = sum + temp;
          Digit d3 = new Digit(temp);
          barCode = barCode + d3.getCode();
          zip = zip % 100;
          temp = zip / 10;
          sum = sum + temp;
          Digit d4 = new Digit(temp);
          barCode = barCode + d4.getCode();
          zip = zip % 10;
          temp = zip;
          sum = sum + temp;
          Digit d5 = new Digit(temp);
          barCode = barCode + d5.getCode();
          temp = 10 - (sum % 10);
          Digit d6 = new Digit(temp);
          barCode = barCode + d6.getCode() + "|";
          return barCode;
       private int zip;
    public BarCode(String aCode)
          code = aCode;
       public int getCode()
          if (code.length() != 2 + 6 * DIGITLENGTH)
            return -1;
          if (!code.substring(0, 1).equals("|"))
             return -1;
          int i = 1;
          int sum = 0;
          int dsum = 0;
          String codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d1 = new Digit(codeDigit);
          int val = d1.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
             return -1;
          sum = sum + val * 10000;
          dsum = dsum + val;
          codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d2 = new Digit(codeDigit);
          val = d2.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
             return -1;
          sum = sum + val * 1000;
          dsum = dsum + val;
          codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d3 = new Digit(codeDigit);
          val = d3.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
             return -1;
          sum = sum + val * 100;
          dsum = dsum + val;
          codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d4 = new Digit(codeDigit);
          val = d4.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
             return -1;
          sum = sum + val * 10;
          dsum = dsum + val;
          codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d5 = new Digit(codeDigit);
          val = d5.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
          return -1;
          sum = sum + val;
          dsum = dsum + val;
          codeDigit = code.substring(i, i + DIGITLENGTH);
          Digit d6 = new Digit(codeDigit);
          val = d6.getCode();
          i = i + DIGITLENGTH;
          if (val < 0)
             return -1;
          dsum = dsum + val;
          if (dsum % 10 != 0)
             return -1;
          if (!code.substring(i, i + 1).equals("|"))
             return -1;
          return sum;
       public boolean isValid()
          return true;
       private final int DIGITLENGTH = 5;
       private String code;
    public class Digit
        public Digit(int n)
          zip = n;
       public String getCode()
          String bar = "";
          if (zip == 1)
             bar = ":::||";
          else if (zip == 2)
             bar = "::|:|";
          else if (zip == 3)
             bar = "::||:";
          else if (zip == 4)
             bar = ":|::|";
          else if (zip == 5)
             bar = ":|:|:";
          else if (zip == 6)
             bar = ":||::";
          else if (zip == 7)
             bar = "|:::|";
          else if (zip == 8)
             bar = "|::|:";
          else if (zip == 9)
             bar = "|:|::";
          else
             bar = "||:::";
          return bar;
       private int zip;
    public Digit(String aCode)
          code = aCode;
       public int getCode()
          if (code.equals(":::||"))
             return 1;
          else if (code.equals("::|:|"))
             return 2;
          else if (code.equals("::||:"))
             return 3;
          else if (code.equals(":|::|"))
             return 4;
          else if (code.equals(":|:|:"))
             return 5;
          else if (code.equals(":||::"))
             return 6;
          else if (code.equals("|:::|"))
             return 7;
          else if (code.equals("|::|:"))
             return 8;
          else if (code.equals("|:|::"))
             return 9;
          else if (code.equals("||:::"))
             return 0;
          else return -1;
       public boolean isValid()
          return false;
       private String code;
    }

    Your squiggly braces are completely out of whack!
    Class definitions should be something like this:class ClassName
        public ClassName()    // one constructor
            // code here
        public ClassName(String someString)    // another constructor
            // code here
        public void someMethod()
            // code here
    class AnotherClass
        public void anotherMethod()
            // code here
    }For each opening curly brace { there must be exactly one closing curly brace }.
    Once you've gotten your curly braced figured out, you can deal with the multiple redefinitions of your methods. One step at a time, though.

  • Help with program hw

    For my intro to programming class I have this program where i have to take 5 names put them in an array, assign 25 scores (given) to a 1d array named temp and move to an array that is 2d with each 5 scores going to a new line (person). Then you must create a function to compute row & column total, high, low, and average. The average drops the lowest grade and doubling the final exam. Then you must create a function to assign a grade letter in a char array. Then call a "drawGraph" function that prints a bar chart for each person that shows their averages. Then print the results in a frame windwo and then call a function that prints the other arrays in table form (with headings).
    I know this is a long post but I cannot get this thing to run and i have typed almost all the code, so any help would be greatly appreciated! This is what i have so far:
    import java.io.*;
    import javax.swing.*;
    import java.net.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Application1
    public static void main()
    JTextArea dataout= new JTextArea(400,50);
    Frame df = new Frame("application frame");
    df.setSize(800,500);
    Graphics g = df.getGraphics();
    int temp[]={34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66};
    int scores[][]=new int[8][8];
    float[]avg=new float[5];
    String name[]={"Mary","John","William","Debbie","Ralph"};
    String out=" ";
    char grade[]=new char[5];
    int c=0;
    int d=0;
    int e=0;
    for (int a=0;a<5;a++)
    for(int b=0;b<5;b++)
    scores[a]=temp[c];
    c++;
    scores[a][6]=200;
    scores[6][a]=200;
    finishscoresarray(scores);
    getAverage(scores,avg,grade);
    prntGraph(g,avg,name);
    prntData(avg,name,grade,scores,out);
    dataout.setText(out);
    JOptionPane.showMessageDialog(null,out);
    public static void finishscoresarray(int[][]scores)
    for(int a=0;a<5;a++)
    for(int b=0;b<5;b++)
    scores[5][a]=scores[5][a]+scores[b][a];
    scores[a][5]=scores[a][5]+scores[a][b];
    if(scores[a][b]<scores[6][a])
    scores[6][a]=scores[a][b];
    if(scores[b][a]<scores[a][6])
    scores[a][6]=scores[b][a];
    if(scores[a][b]>scores[7][a])
    scores[7][a]=scores[a][b];
    if(scores[b][a]>scores[a][7])
    scores[a][7]=scores[b][a];
    public static void getAverage(int[][]score, float[]avg, char[]grade)
    for(int a=0;a<5;a++)
    avg[a]=((score[a][5]-score[a][6]+score[a][4])/5);
    if(avg[a]>89)
    grade[a]='A';
    else if(avg[a]>79)
    grade[a]='B';
    else if(avg[a]>69)
    grade[a]='C';
    else if(avg[a]>59)
    grade[a]='D';
    else
    grade[a]='F';
    public static void prntGraph(Graphics g, float[]avg, String[]name)
    for(int a=0;a<5;a++)
    g.drawString(name[a],(int)100*(a+1),100);
    g.drawRect(80*(a+1),80*(a+1),(int)avg[a],40);
    public static void prntData(float[]avg,String[]name,char[]grade,int[][]scores,String out)
    for(int a=0;a<7;a++)
    out=out+name[a]+" "+scores[0][a]+" "+scores[1][a]+" "+scores[2][a]+" "+scores[3][a]+" "+scores[4][a]+" "+scores[5][a]+" "+scores[6][a]+" "+scores[7][a]+" "+avg[a]+" "+grade[a]+"\n";
    Thanks!

    but I cannot get this thing to runexplain what it is you expect to happen
    e.g.
    do you enter some numbers and the output is wrong
    does it not compile/run
    also, so that people can read the code, repost it, but use the code tags to preserve the formatting
    ie click on the code button, which will produce
    [code][/code]
    and paste your code between the two tags

  • Help with FCP and long project editing - Thanks!

    I have posted several questions in this discussion group and in the iMovie group to no avail. I get a lot of answers, but not from anyone who has actually done any of the editing I am seeking. So if anyone has actually done the editing I am describing below -- I appreciate your help. Yes, I have searched the archives -- but again, I see a lot of confusing feedback. I have been working on this for three days now and it's driving me crazy! I have discovered that iMoive is $#@% -- and does not work with a long project, (40 minutes) so I am thinking about switching to FCP-HD. Thanks.
    Here goes:
    1: I need to transfer original master footage, 1080i HDV from a Sony HDR-FX1 to an editing program, edit the tapes (over 5 hours total) into a 50 minute "program". I then need to "share" or export the footage back to a new tape, using the Sony HDR-FX1 as the receiving camera. Simple enough.
    2: I need to make sure the outgoing footage is of equal quality as the original footage taken from the camera. I am guessing here, that the footage can be edited in FCP-5 as "native" -- then transferred back to the Sony?
    3: I am assuming that the native footage is just that -- and will not require the long process of converting to another format, e.g., ASI that takes hours to
    render. (as in iMovie).
    4: I am assuming I can edit and view HDV as native footage in FCP in real time, like iMovie, via firewire from the camera?
    I really appreciate any assistance.
    Chance

    Welcome to the family, you'll be joining us soon.
    The FCP product page says: > It features powerful new multicamera editing, native HDV support, ... edit everything from DV and SD to DVCPRO HD and fully uncompressed 10-bit high-definition video. Or work with new formats like native HDV (long-GOP MPEG2) and 50Mbps IMX... HD editing requires a 1GHz or faster PowerPC G4 or G5 and 1GB of RAM (2GB recommended).<
    You seem to have the hardware including the Flux-o-pator, but, really, you want to talk to an Apple reseller who handles FCP and understands HDV via Sony. I don't like the way you're using "I am assuming..." You can't assume anything. Give them a chance to sell you FCP or Studio and go demo your camera on their system. You will have concrete evidence of the minimum machine specs and how well you can get your files in and out of the application.
    Call you local Mac user group and try to locate other FCP users.
    Try also the creativecow.net forums for Sony HD products.
    Google your camera model for support groups.
    bogiesan

Maybe you are looking for

  • WRT160N with PS3 "IP Fragments..."

    A run down... I've spent many hours googling trying to figure out what the problem is and I cant seem to find out. Hopefully someone here can give me a hand. When I run connection tests on my PS3 i'm getting NAT type 2... but! It says "The router in

  • TitledBorder Text is Truncated

    Hello all, This must be a common problem. Here's a simple version of the problem: I have a JPanel using a FlowLayout. Within the JPanel I have a JLabel whose text is a single character in length. When I place a TitledBorder around the JPanel, the bor

  • Plant Authorization

    Hi,   I was trying to restrict the user to get data for spefic plant . Is their a std approach to do this. I would like to have this restriction to custom programs/reports only. Awaiting a reply

  • How to sharpen in photos

    <sigh> Am I correct in thinking that Sharpening is another "feature" that isn't present in Photos? So if not, not a problem, as you can always do that using an external editor like in dear old iPhoto - except of course you can't, as that's another ap

  • HT4623 I don't have the option to for a "software update"

    I'm trying to upgrade my iTouch to IOS 5.  It doesn't give me an option for a "software update" in general settings...it is a gen 2 itouch...is it too old?