BreezySwing help requested (should be very simple)

My final project for my beginning programming class is to create a calculator, much like the one built into Windows. It only needs to do what the basic one does, not the scientific.
All I have so far is the GUI. The buttons do nothing yet.
////////////////////////////-A-//////////////////////////////////
///////////////////////-CALCULATOR-//////////////////////////////
//////////////////////-FINAL PROJECT-////////////////////////////
//////////////////////////-FOR-//////////////////////////////////
///////////////////////-MR. KAU'S-///////////////////////////////
/////////////////-INTRODUCTION TO COMPUTERS-/////////////////////
//////////////////////////-CLASS-////////////////////////////////
//Imports
import javax.swing.*;
import BreezySwing.*;
//Title
public class Calculator extends GBFrame{
//Vars
private JButton CB, SevenB, EightB, NineB, DivideB, SquareRootB,
FourB, FiveB, SixB, TimesB, PercentB, OneB, TwoB, ThreeB, MinusB,
OneOverXB, ZeroB, NegativeB, DecimalB, AddB, EqualB;
private DoubleField Window;
//Constructor
public Calculator(){
//Fields
Window = addDoubleField   (0    ,1,1,5,1);
//Buttons
CB = addButton ("C" ,2,3,1,1);
SevenB = addButton ("7" ,3,1,1,1);
EightB = addButton ("8" ,3,2,1,1);
NineB = addButton ("9" ,3,3,1,1);
DivideB = addButton ("/" ,3,4,1,1);
SquareRootB = addButton ("sqrt" ,3,5,1,1);
FourB = addButton ("4" ,4,1,1,1);
FiveB = addButton ("5" ,4,2,1,1);
SixB = addButton ("6" ,4,3,1,1);
TimesB = addButton ("*" ,4,4,1,1);
PercentB = addButton ("%" ,4,5,1,1);
OneB = addButton ("1" ,5,1,1,1);
TwoB = addButton ("2" ,5,2,1,1);
ThreeB = addButton ("3" ,5,3,1,1);
MinusB = addButton ("-" ,5,4,1,1);
OneOverXB = addButton ("1/x" ,5,5,1,1);
ZeroB = addButton ("0" ,6,1,1,1);
NegativeB = addButton ("+/-" ,6,2,1,1);
DecimalB = addButton ("." ,6,3,1,1);
AddB = addButton ("+"  ,6,4,1,1);
EqualB = addButton ("=" ,6,5,1,1);
//Button Method, yo
public void buttonClicked (JButton buttonObj){
//EXE-CUTE-R OLO!!1!
public static void main (String[] args){
Calculator SCGUI = new Calculator();
SCGUI.setLookAndFeel("MOTIF");
SCGUI.setSize (250, 250);
SCGUI.setVisible (true);
} I'm sure there are easier ways to go about it than using BreezySwing, but that's what we were taught with, so... :sweat:
I'm drawing a total blank on how to do this with a single Field. If someone could guide me in the correct direction, it would be much appreciated. I'm not asking for someone to finish my program, maybe just make it so it will add, and from that I'll figure out the division, multiplication, sqrt, etc. etc.
Thanks in advance.

Alright.
I now seem to have come across a different problem. Being VERY new to Java, I am unable to make it so that the numbers 'add up' so to speak in the field. I press 5 and 5 shows up. I press 6, and 6 replaces the 5.
if (buttonObj == TwoB){
Window.setNumber(2.0);
}I know that using setNumber will end up replacing it, but I'm not even sure how to get it so that when I press the 5 key, then the 6 key, that 56 will be in the field.
Would I use getNumber, and then somehow add the setNumber? Should I not use setNumber at all?

Similar Messages

  • HELP, most probably a very simple solution!

    I can compile the following file but I can't get it to run. I know something very simple is needed but I am still learning this java business and am currently brain dead. Please help as this is quite important for me! Any advice is much appreciated, thanks. It is basically meant to be a program to give co-ordinates in a JPanel etc... Please don't abuse me for not understanding!!! lol
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    //import com.borland.jbcl.layout.*;
    public class Picker extends JPanel
         String imageFile = "Images/knob.jpg";
         // Create JPanel and set the dimensions so that the crosshairs go in the right place
         Image img = Toolkit.getDefaultToolkit().getImage(imageFile);
         JPanel hSPickerPanel = new JPanel()
              public Dimension getPreferredSize(){return new Dimension(100, 100);}
              public Dimension getMaximumSize(){return getPreferredSize();}
              public Dimension getMinimumSize(){return getPreferredSize();}
              //PaintComponent method for this JPanel Component. Each component needs
              //its own so that each can be redrawn.
              public void paintComponent(Graphics g)
                   super.paintComponent(g);
                   //     Graphics2D g2D = (Graphics2D)g;
                   g.setClip(0, 0, getSize().width, getSize().height);
                   // g2D.drawImage(BC, null, 0, 0);
                   g.setXORMode(Color.WHITE);
                   //Problem.
                   // Draws the cross relating to the coordinates of the whole JPanel.
                   // Not hSPickerPanel. Sorted. 01/08/03. each panel wants to have its
                   //own paintComponent method.
                   g.drawImage(img, xCoord, yCoord,15,15,this);
                   // g.drawOval(xCoord, yCoord, 15, 15);
                   //g.fillOval(xCoord, yCoord, 15,15);
                   // g.drawLine(xCoord + 10 , yCoord,xCoord - 10 , yCoord);
                   // g.drawLine(xCoord, yCoord + 10, xCoord, yCoord - 10);
                   g.drawString(String.valueOf(xCoord) + ":" + String.valueOf(100 - yCoord), 54, 47);
         JLabel HueSatTitleLabel = new JLabel();
         JLabel hueSatLabel = new JLabel();
         int xCoord = 50;
         int yCoord = 50;
         String coordinates;
         String xString;
         String yString;
         GridBagLayout gridBagLayout1 = new GridBagLayout();
         JButton jButton1 = new JButton();
         public Picker()
              try
                   jbInit(); // calls the method below that adds the button to 'this'
              catch(Exception e)
                   e.printStackTrace();
         //dddddddddddddddddddddddddddddddddddddddddddddddddddddddd
         // BrtnsCtrstPckrPnl = new JPanel() creates JPanel.
         //     public void paintComponent(Graphics g)
         /*     super.paintComponent(g);
                   Graphics2D g2D = (Graphics2D)g;
                   g2D.setClip(0, 0, getSize().width, getSize().height);
                   // g2D.drawImage(BC, null, 0, 0);
                   g2D.setXORMode(Color.WHITE);
                   g2D.drawLine(xCoord - 10, yCoord, xCoord + 10, yCoord);
                   g2D.drawLine(xCoord, yCoord - 10, xCoord, yCoord + 10);
                   g2D.drawString(String.valueOf(xCoord) + ":" + String.valueOf(100 - yCoord), 54, 47);
         /*          super.paintComponent(g);
                   //     Graphics2D g2D = (Graphics2D)g;
                             g.setClip(0, 0, getSize().width, getSize().height);
                             // g2D.drawImage(BC, null, 0, 0);
                             g.setXORMode(Color.WHITE);
                             g.drawLine(xCoord + 10 , yCoord,xCoord - 10 , yCoord);
                             g.drawLine(xCoord, yCoord + 10, xCoord, yCoord - 10);
                             g.drawString(String.valueOf(xCoord) + ":" + String.valueOf(100 - yCoord), 54, 47);
         //ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
         private void jbInit() throws Exception
              this.setLayout(gridBagLayout1);
              hSPickerPanel.setBorder(BorderFactory.createEtchedBorder());
              HueSatTitleLabel.setBorder(BorderFactory.createEtchedBorder());
              HueSatTitleLabel.setText("Hue & Saturation");
              hueSatLabel.setBorder(BorderFactory.createEtchedBorder());
              xString = Integer.toString(xCoord);
              yString = Integer.toString(yCoord);
              coordinates = xString +" : "+ yString;
              hueSatLabel.setText(coordinates);
              hSPickerPanel.addMouseListener(new MouseAdapter()
                        public void mouseReleased(MouseEvent e)
                             xCoord = Math.max(Math.min(e.getX(), 100), 0);
                             yCoord = Math.max(Math.min(e.getY(), 100), 0);
                             displayCoordinates(xCoord,yCoord);
                             hSPickerPanel.repaint();
                        public void mousePressed(MouseEvent e)
                             xCoord = Math.max(Math.min(e.getX(), 100), 0);
                             yCoord = Math.max(Math.min(e.getY(), 100), 0);
                             displayCoordinates(xCoord,yCoord);
                             hSPickerPanel.repaint();
              hSPickerPanel.addMouseMotionListener(new MouseMotionAdapter()
                        public void mouseDragged(MouseEvent e)
                             xCoord = Math.max(Math.min(e.getX(), 100), 0);
                             yCoord = Math.max(Math.min(e.getY(), 100), 0);
                             displayCoordinates(xCoord,yCoord);
                             hSPickerPanel.repaint();
              //Add components to Back Panel (this)
              this.setMaximumSize(new Dimension(118, 165));
              this.setMinimumSize(new Dimension(118, 165));
              jButton1.setText("Reset");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             jButton1_actionPerformed(e);
              this.add(hSPickerPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0
                   ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 3, 0, 0), 101, 102));
              this.add(HueSatTitleLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
                   ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 3, 0, 0), 30, 1));
              this.add(hueSatLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
                   ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 5, 0), 4, 3));
              this.add(jButton1, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
                   ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 3, 0));
         public void displayCoordinates(int x, int y)
              xString = Integer.toString(x);
              yString = Integer.toString(y);
              coordinates = xString +" : "+ yString;
              hueSatLabel.setText(coordinates);
         void jButton1_actionPerformed(ActionEvent e)
              xCoord = 50;
              yCoord = 50;
              displayCoordinates(xCoord, yCoord);
              hSPickerPanel.repaint();

    Use a URL object to locate your image instead of a string. To do that, import the java.net.* library and create a URL object for your image:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    //import com.borland.jbcl.layout.*;
    import java.net.*;
    public class Picker extends JPanel
        //String imageFile = "Images/knob.jpg";
        Class cl = ((Picker) this).getClass();
        URL imageURL=cl.getResource("Images/knob.jpg");
        // Create JPanel and set the dimensions so that the crosshairs go in the right place
        Image img = Toolkit.getDefaultToolkit().getImage(imageURL);
        JPanel hSPickerPanel = new JPanel()
    }To view your Panel, you have to add a "main" method and create a frame to display your panel:
    public class Picker extends JPanel
        void jButton1_actionPerformed(ActionEvent e)
        public static void main(String[] args)
         Picker p=new Picker();
         JFrame frame=new JFrame("Picker Example");
         frame.getContentPane().add(p);
         frame.setVisible(true);
         frame.pack();
    }You can see your panel by:
    - compiling: javac Picker.java
    - and running your application with the "main" method: java Picker

  • This should be very simple...

    using the usb 9171 chassis and a ni-9411 module and Labview 2012
    I have one reflective optical reader wired to the 9411.
    this is mounted to the side of a conveyor bed to detect boxes passing by
    I've been trying to setup a VI to count the number of boxes that pass by the optical reader (that part is the easy part) but to also give me a gage that tells me boxes per minute (which could be as low as 1 box passes by per minute or up to 60 boxes per minute)
    any help??

    You could set up a frequency measurement task to do this.
    The tricky part is that the read is a blocking call--it waits until you have a sample available which only happens when a box passes by (starting with the 2nd box, the frequency measurement is computed by inverting the time between consecutive boxes).  You don't want to be stuck inside the DAQmx Read call for up to 1 minute.  A few ways to go about this:
    You can set the read timeout to some low value and discard the timeout error (-200284).  If you're using too much CPU you might need to add a wait to your loop in the timeout case (or maybe this is one of the rare times that setting the DAQmx Read Wait Mode to "Sleep" might actually help).
    You could poll the available samples per channel property to see when to read, but unfortunately polling available samples per channel does not query the onboard FIFO or initiate a transfer back to the software buffer (last I checked), so you'll be reading "0" for quite some time until the on-board FIFO starts filling up, at which point a large chunk of data will be transferred back to the DAQmx buffer in PC memory at once.  Note that this does not apply to PCI/PCIe DAQ devices which transfer data to the PC buffer pretty much as soon as possible--USB and Ethernet devices try to minimize the overhead of unnecessary data transfers but in this case it is a hindrance.
    Using the DAQmx Every N Samples event has the same problem as #2.
    Reading -1 samples returns whatever is in the DAQmx buffer in PC memory, so it also has the same problem as #2 (the read will return 0 samples until the hardware decides to transfer the data over to the PC).
    In your case, you might have luck with #2, #3, or #4 by setting the CI.DataXferReqCond to "Onboard Memory not Empty", but without being able to validate any of these workarounds I think I'm just going to recommend you use suggestion #1:
    You can either run this task in addition to your current edge count task (there are 4 counters on the 9171 which should be plenty given you can only have 1 module), or you can run it instead of it (poll back the Total Samples per Channel and add 1 to determine the count of boxes, however you wouldn't be able to distinguish between 0 and 1 boxes this way since the first sample is returned after the 2nd box passes).
    Best Regards,
    John Passiak

  • Plz help me on this very simple error

    hello everybody...i'm very new to java programming...i'm unable to execute my program though it has been compiled...my coding is something like this and is very easy>>
    class abc
    public static void main(String [] args)
    System.out.println("hello");
    and at the time of execution...this error is shown up>>
    C:\Documents and Settings\Ishan\Desktop>java abc
    Exception in thread "main" java.lang.NoClassDefFoundError: abc
    Caused by: java.lang.ClassNotFoundException: abc
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: abc. Program will exit.
    plz help me on this. thanks.

    Follow the instructions in this tutorial:
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
    See problem solutions here:
    http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html

  • HELP please.. Very simple, but I can't do it...

    Hi,
    How can i make and int be between 1 and 10? I'm using bluej. So I'm declaring the variable enjoyability as an int and then starting directly in the constructor like:
    public class Book
    private String author;
    private String title;
    private String cost;
    private String numberOfPages;
    private int enjoyability;
    private String genre;
    public Book(String author, String title, String cost, String numberOfPages, int enjoyability, String genre)
    this.author = author;
    this.title = title;
    this.cost = cost;
    this.numberOfPages = numberOfPages;
    this.enjoyability = enjoyability;
    this.genre = genre;
    public String author()
    return author;
    public String title()
    return title;
    public String cost()
    return cost;
    public String numberOfPages()
    return numberOfPages;
    public int enjoyability()
    return enjoyability;
    public String genre()
    return genre;
    public void print()
    System.out.println("\n############ LIBRARY ############");
    System.out.println("----------Book Details-----------");
    System.out.println(" Author: " + author() );
    System.out.println(" Title: " + title() );
    System.out.println(" Cost: " + cost() );
    System.out.println(" Number of pages: " + numberOfPages() );
    System.out.println(" Enjoyability: " + enjoyability() );
    System.out.println(" Genre: " + genre() );
    and then I have another class that stores the book I made and print it to the console:
    public class Library
    private ArrayList items;
    * Constructor for objects of class Library
    public Library()
    items = new ArrayList();
    public void addBook(Book newBook)
    items.add(newBook);
    public void alphaAdd()
    public int numberOfItems()
    return items.size();
    public void print()
    for(Iterator iter = items.iterator(); iter.hasNext(); ){
    Book book = (Book)iter.next();
    book.print();
    System.out.println();
    How can i limited it to be between 1 and 10?? Thanks

    public class Book
    private String author;
    private String title;
    private String cost;
    private String numberOfPages;
    private int enjoyability;
    private String genre;
    public Book(String author, String title, String cost, String numberOfPages, int enjoyability, String genre)
    this.author = author;
    this.title = title;
    this.cost = cost;
    this.numberOfPages = numberOfPages;
    this.enjoyability = enjoyability;
    this.genre = genre;
    public String author()
    return author;
    public String title()
    return title;
    public String cost()
    return cost;
    public String numberOfPages()
    return numberOfPages;
    public int enjoyability()
    return enjoyability;
    public String genre()
    return genre;
    public void print()
    System.out.println("\n############ LIBRARY ############");
    System.out.println("----------Book Details-----------");
    System.out.println(" Author: " + author() );
    System.out.println(" Title: " + title() );
    System.out.println(" Cost: " + cost() );
    System.out.println(" Number of pages: " + numberOfPages() );
    System.out.println(" Enjoyability: " + enjoyability() );
    System.out.println(" Genre: " + genre() );
    and then I have another class that stores the book I made and print it to the console:
    public class Library
    private ArrayList items;
    * Constructor for objects of class Library
    public Library()
    items = new ArrayList();
    public void addBook(Book newBook)
    items.add(newBook);
    public void alphaAdd()
    public int numberOfItems()
    return items.size();
    public void print()
    for(Iterator iter = items.iterator(); iter.hasNext(); ){
    Book book = (Book)iter.next();
    book.print();
    System.out.println();
    }

  • Help!!  2 very simple questions about Tomcat 5

    1. How can I run a servlet within a package?
    * I add the package to Tomcat 5.0\webapps\servlets-examples\WEB-INF\classes
    * I add the following to Tomcat 5.0\webapps\servlets-examples\WEB-INF\web.xml
    <web-app>
    <servlet>
    <servlet-name>ServletName</servlet-name>
    <servlet-class>Package.ServletName</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletName </servlet-name>
    <url-pattern> /servlet/ServletName </url-pattern>
    </servlet-mapping>
    </web-app>
    * I type in the address line the following:
    http://localhost/servlets-examples/servlet/ServletName
    But it does not work!
    2. I can run servlets and JSP files only when they are saved inside the following packages:
    Tomcat 5.0\webapps\servlets-examples\
    Tomcat 5.0\webapps\jsp-examples\
    How can I make my own folder if I want to use Tomcat 5?
    Any answer will be appreciated. Thanks in advance!

    1. How can I run a servlet within a package?
    Define package XXX for your servlet
    For eg : package xxx;
    class ServletTest extends HttpServlet
    * I add the package to Tomcat
    5.0\webapps\servlets-examples\WEB-INF\classes
    * I add the following to Tomcat
    5.0\webapps\servlets-examples\WEB-INF\web.xml
    <web-app>
    <servlet>
    <servlet-name>ServletName</servlet-name>
    <servlet-class>Package.ServletName</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletName </servlet-name>
    <url-pattern> /servlet/ServletName
    letName </url-pattern>
    </servlet-mapping>
    </web-app>
    * I type in the address line the following:
    http://localhost/servlets-examples/servlet/ServletName
    But it does not work!
    http://localhost/servlets-examples/servlet/ServletName
    What is the error being thrown here >>> 404 not found?
    2. I can run servlets and JSP files only when they are
    saved inside the following packages:
    Tomcat 5.0\webapps\servlets-examples\
    Tomcat 5.0\webapps\jsp-examples\
    How can I make my own folder if I want to use Tomcat
    5?
    create a folder under webapps for eg :
    myfirstapp
    and follow a similar directory structure that has been followed for the example applications.Register your context with the server.xml located at tomcat\conf\server.xml
    -Regards
    manikantan

  • Okay.... this should be very simple

    when i click on a text file... .php or .tcl or .c or whatever.... when i click on the source file i want it to open in a new console window in vi ....
    except from the command line i can;t even FIND vi or vim or gvim on this box...
    so, how do i associate text files with a given extension with vi (or the mac equivalent) so i can get some work done????

    The extension is of little relevance in Mac world. Find the file you want to open, Highlight it. Cick cnd+I. In the box that opens, down click the Open With triangle. Either select the applicatrion you want, or navigate to the application you want to open this. Thyen, hot "Change All.
    Is this what you want. I really have no idea what all the extensions are.

  • I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    Why do you need a expensive MacBook Pro?
    Your attending high school and unless everyone else is rich also your likely going to be a target by the more poorer students for theft or damage to the machine.
    You could keep it home, but if you need it for class then your exposed again.
    Also at that age your not very careful yet, a MacBook Pro is a expensive and easily damaged machine.
    Unless your made of money and so are others at your school, I would recommned a low profile, just does the job cheap Windows PC.
    If it dies, gets lost, stolen or damaged because of your inexperince handling senstivie electronics then it's no big deal.
    You can buy a Mac later on when your sure you have a need for it, currently there isn't much advantage of owning a Mac compared to a PC, they do just about the same things now, one just looks prettier than the other.
    Since 95% of the world uses Windows PC's your going to have to install Windows on the Mac in order to keep your skills up there or be unemployed, so it's a extra headache and expense.
    good luck

  • HT1800 How can I add a Epson Stylus SX445w to my mac Book Pro this is the second one I've tried and failing miserably...it should be so simple...spoken to the help line at Epson and they say it's down to Apple !! Somebody please help me

    How can I add a Epson Stylus SX445w to my Mac Book Pro
    This is the second one I've tried and failing miserably...it should be so simple...I've installed poken to the help line at Epson and they say it's down to Apple !! Somebody please help me

    Yes I did everything that I was instructed to do!
    Cheers
    Joyce

  • Very Simple Problem-- Need help in method selection process

    Hello,
    It's difficult to explain the background of the program I am making-- but I am stuck at a very simple problem, that I can only solve with a very long block of if statements:
    I have 3 possible numbers-- 1, 2, or 3.
    Imagine two numbers are already taken-- say 1 and 2. I want a variable to set itself to the number that's not taken (3).
    So, again: If two numbers were taken say 2 or 3-- I want the variable to be sent to the other one that isn't taken-- 1.
    Thank you for your help,
    Evan.

    Actually, I'll just tell you the context of the program-- here is what I have so far:
    This program is meant to simulate Monty Hall Problem:
    http://en.wikipedia.org/wiki/Monty_Hall_problem
    The program sets up an array of three possible values. Each one of those values represents a door with either a goat or a car behind it. It then randomly sets one of those values to 1 (in order to represent a car as per the Monty Hall problem), and 0's represent goats.
    The user, which is simulated by the program (does not involve actual interaction), chooses a door initially.
    The game show hosts then reveals a door that is not the users initial choice, but IS a goat ( an array value of 0).
    For example if the array was [0][0][1]
    The user could pick door one (array position 0). Which is a goat.
    The game show host then reveals a goat that is not the users choice-- which would be array position 1.
    After the game show host reveals the goat-- I want the user to always switch his decision to the only other remaining door that was not his first choice.
    Then I wanted the computer to test to see if his final choice is the one with a car. And to tally up the amount of times he got it right.
    --Sorry that was long winded:
    import TerminalIO.*;//imports TerminalIO package for system.out.println
    import java.util.*;//import java.util for random
    public class Monty_Problem
         int doors[]= {0,0,0};
         Random rand= new Random();
         double wins,totals=0;
         public void carAssignment()
              int car_door= rand.nextInt(3);
              doors[car_door]=1;
         public int judgesChoice(int judgeDoor, int initialChoice)
              if(judgeDoor != initialChoice && doors[judgeDoor]!=1)
                   return judgeDoor;
              else
                   return judgesChoice(rand.nextInt(3), initialChoice); //infinite loop right here that I cannot remedy.  I want the program to have the judge pick a location that is not occupied by a  '1' and is not the user's choice. 
         public void gamePlaySwitches()
              int initialChoice= rand.nextInt(3);
              int judgeDoor = 0;
              int secondChoice= 0;
              judgeDoor= judgesChoice(rand.nextInt(3), initialChoice);
              //This part is meant to have the user switch choices from his initial choice
                   // to the only other choice that hasn't been revealed by the judge. 
              while(secondChoice == initialChoice || secondChoice== judgeDoor)
                   secondChoice++;
              if(doors[secondChoice]==1)
                   wins++;
                   totals++;
              else
                   totals++;          
         public static void main(String [] args)//creates the main menu
              Monty_Problem a= new Monty_Problem();
              int games=0;
              while(games!=100)
                        a.carAssignment();
                        a.gamePlaySwitches();
                        games++;
              System.out.println(a.wins/a.totals);
    }Edited by: EvanD on Jan 11, 2008 4:17 PM

  • Need help with a very simple example.  Trying to reference a value

    Im very new to Sql Load and have created this very simple example of what I need to do.
    I just want to reference the ID column from one table to be inserted into another table as DEV_ID.
    Below are my: 1) Control File, 2) Datafile, 3) Table Description, 4) Table Description
    1) CONTROL FILE:
    LOAD DATA
    INFILE 'test.dat'
    APPEND
    INTO TABLE p_ports
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    DEV_id REF(CONSTANT 'P_DEVICES',NAME),
    NAME FILLER ,
    PORT_NO
    2) DATAFILE:
    COMM881-0326ES09,6
    3) TABLE DESCRIPTION:
    SQL> describe p_ports
    Name Null? Type
    ID NOT NULL NUMBER(10)
    DEV_ID NOT NULL NUMBER(10)
    PORT_NO     NUMBER(3)

    hi,
    i managed to do this for my app. (think i referred to viewTransitions sample code and modified quite a bit)
    i can't remember this well cos i did this quite a while back, but i will try to help as much as possible
    1) from the appdelegate i initialize a root controller (view controller class)
    2) this root controller actually contains two other view controllers, let's call it viewAController and viewBController, for the screens which u are going to toggle in between. and there's also a function, let's call it toggleMenu, which will set the menus to and fro. i copied this whole chunk from the sample code. it actually defines the code on what to do, i.e. if current view is A switch to B and vice versa.
    3) inside the controller files, you need to implement the toggleMenu function too, which basically calls the rootController's toggleMenu
    4) we also need viewA and viewB files(view class)
    5) need to add the .xib files for the respective views and link them up to the controller class. i did not use the .xib files for ui layout though, because of my app's needs. however, it will not work properly without the .xib files.
    5) inside the view class of both views, i.e. viewA.m and viewB.m, you need to create a button, that will call the toggleMenu function inside the respective controller class.
    it will look something like this:
    [Button addTarget:ViewAController action:@selector(toggleMenu:) forControlEvents:UIControlEventTouchUpInside];
    so the flow is really button (in view)-> toggleMenu(viewController) -> toggleMenu(rootController)
    i'm sorry it sounds pretty hazy, i did this part weeks before and can't really remember. i hope it helps.

  • PDF - Very Simple Request

    How can I move PDF files from my MacBook Pro to my iPad so that I can read them there? There seems to be no easy way to do this. I even purchased Pages, only to find out that you can't read PDF files in that program. This seems like a very simple thing to do but, apparently, it isn't. Can anyone help out here?

    I bought PDF Reader Pro for the iPhone/iPod Touch and it offers a way to put the app in a Wifi sharing mode. I then navigate to it with my Mac in Safari, nagivate to the displayed IP address on the iPod Touch and then click the upload button. They don't have a iPad version yet.
    Look for other apps that offer this simple way of PDF file transferring or check with the PDF Reader Pro developers.
    Remember - Each iPad app cannot share it's data space with other apps so if you use a PDF reader app I believe only that app can read the files...
    Sincerely,
    G.
    <Edited by Host>

  • Can't run very simple DOM parsing source on my machine - please help :(

    Hi Guys,
    I am trying to run the following very simple program on my machine to parse a very simple XML file.
    It just returns Document object NULL.
    Same code is working fine on another machine.
    Note: there is no silly mistake. i have valid xml file at valid place.
    Please help.
    import org.apache.xerces.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import java.io.*;
    class XML
         public static void main(String[] args)
              try{
                   String caseFile = "c:\\case-config\\config.xml";
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setValidating(true);
                   DocumentBuilder builder = factory.newDocumentBuilder();
                   Document doc = builder.parse(caseFile);
                   System.out.println("\n\n----" + doc);
              }catch(Exception e)
                   e.printStackTrace();
    }

    You could also work with JDOM, which I find easier to use than regular DOM:
    import org.xml.sax.InputSource;
    import java.io.FileReader;
    import org.jdom.input.SAXBuilder;
    import org.jdom.Document;
    String caseFile = "c:/case-config/config.xml";
    InputSource inputSource = new InputSource(new FileReader(caseFile));
    SAXBuilder builder= new SAXBuilder();
    Document document = builder.build(inputSource);Just an alternate suggestion.

  • Help: Very simple HTTPService issue

    I have created very simple test :
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute"
    width="100%" height="100%">
    <mx:Script><![CDATA[
    import mx.rpc.http.HTTPService;
    [Bindable]
    public var srv:HTTPService;
    ]]></mx:Script>
    <mx:Label text="Is it working?" />
    </mx:Application>
    This application is rendered by tomcat here :
    http://jc.studiogdo.com (you can
    test)
    As the HTTPService is declared, you can see that nothing is
    rendered!!!! On a local machine (tomcat running on my localhost)
    then it works on IE. On real server like this example nothing
    works!!! Of course without declaring the HTTPService everything
    works... I've created this example with Flex Builder2 on eclipse
    useProxy is false, so no need for a crossdomain.xml... Where
    is the error????
    Many thanks for help..

    The issue is that : declaring the HTTPService stops the
    player (even if the play parameter is set to true for the embed
    object) when the application is served from a tomcat server (not a
    local file), so it works only if I forces (right menu) the play
    menu item.
    What happens :
    On a local file : FF and IE accepts to autoplay the
    application
    On a local tomcat (localhost url) : FF refuses to auto play,
    IE accepts.
    On a real distant tomcat server : FF and IE refuses to
    autoplay
    I think this is for security reason? But how to force the
    play parameter to be used anyway... (I repeat to be sure
    understanding : the simple HTTPService declaration changes the way
    the play parameter is evaluated..)

  • Need help with something VERY SIMPLE

    I'm brand new to Motion - as if today - but I'm only trying to do some VERY simple motions with photos - a simultaneous zoom in and reposition. What I've been doing is setting the starting key frame at one position (adjusting the x, y) and setting the scale. Then I create a second key frame and adjust the postion and scale. It will do the zoom, but then it re adjusts the starting position. If I readjust the starting key frame, it automatically readjusts the second key frame. I don't get it! Applying the various 'behaviors' doesn't seen to help. Certainly there's something obvious here that I'm missing - as I was able to do this in FCP. For some reason the key frames are not fixed when it comes to position.

    hi,
    a couple of thoughts?
    did you actually set a keyframe for position at the first frame?
    Also unless you are parked right on a keyframe or have the record button on, if you adjust a value, all the values for all keyframes adjust accordingly. I often mess something up because I wasnt parked on a keyframe.
    hth
    adam

Maybe you are looking for

  • HP LaserJet Pro MFP M521dn - won't install scanner

    When I install the HP LaserJet Pro MFP M521dn, it installs to my mac desktop running Yosemite only as a printer.  None of the scanning functions are accessible and it doesn't show up when HP Scan or Image capture are opened.  In system preferences, i

  • External hard drive doesn't show after upgrade to Yosemite

    I upgraded to Yosemite and now my WD 1TB external HD doesn't show up on my MacBook Pro 2.9 GHz.  It shows in the system information under 'About This Mac', but I can't access it.  So I can't use Time Machine to do any back-ups, and I can't back up th

  • STREAMS bug

    Did some work on Solaris 7 hme Fast Ethernet Driver. Believe I found a bug in STREAMS code dealing with priority bands. In short -> modified hme driver to send priority band info over wire - goal was to experiment with STREAMS priority bands for appl

  • To create an executable of java

    that it programs I can use to create the executable of java

  • To access a table in quality from Dev

    Hi All,   Is it possible to get the data from a table in quality or production thorough a program in development, If yes then please tell how?