Identifying colors in a picture (new at java)

Hi everyone, it's been a while.
Now onto the problem. I'm tring to reconize certain parts of a picture as what color they are is there a way for java to look in a picture and identify at as any pixel and say hey it's (22,33,45) color at this part?
thanks

Here is some1's reply I found some time ago (Note img is of BufferedImage type) :
Code to extract pixel :
int pixel=img.getRGB(x,y);
This is the code to extract RGB values from the pixel :
red=(pixel>>16) & 0xff ;
green=(pixel>>8) & 0xff ;
blue=pixel & 0xff ;
To combine RGB values again to a pixel value :
pixel = 255<<24 | red<<16 | green<<8 | blue;
To place the pixel back on the image :
img.setRGB(x,y,pixel);

Similar Messages

  • New to java - glitch in my program/game? should be a simple fix :)

    hey everyone, I'm a student who's new to java programming :) It's is also the first programming language that I'm learning. I know the basics, but nothing very complicated.
    I'm making a pong-like game, in an applet.
    As I was making the paddle and using a mouselistener to make it move vertically, I came across this problem, the paddle will move vertically with the mouse's position, but one end of my paddle will grow abnormally (I want it to stay the same size as it moves up and down)
    Here's my code: (I'm not using most of the mouselistener and keylistener classes yet, so you can ignore them. I'm guessing the problem is probably in one of the last classes, at the bottom)
    ypaddle is the variable used for getting the co-ordinates of the mouse and transferring them to the paddle itself
    // The "Ping" class.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    *Ping
    public class Ping extends Applet
        implements KeyListener, MouseListener, MouseMotionListener
        int width, height, x, ypaddle;
        Graphics g;
        char move;
         *Initializes variables
        public void init ()
            resize (700, 500);
            setBackground (Color.white);
            addKeyListener (this);
            addMouseListener (this);
            addMouseMotionListener(this);
        public void keyPressed (KeyEvent e)
        public void keyReleased (KeyEvent e)
        public void keyTyped (KeyEvent e)
        public void mouseEntered (MouseEvent e)
        public void mouseExited (MouseEvent e)
        public void mousePressed (MouseEvent e)
        public void mouseReleased (MouseEvent e)
        public void mouseClicked (MouseEvent e)
        public void mouseMoved (MouseEvent e)
            ypaddle = e.getY ();
            repaint();
        public void mouseDragged (MouseEvent e)
        public void paint (Graphics g)
            paddle (g, ypaddle);
         * Creates the paddle for hitting the ball
         *@param    y   value used to move the paddle vertically
        public void paddle (Graphics g, int y)
            g.fillRect (10, 10+y, 15, 60+y);
    } // Ping classI'm totally stumped, I've tried for 2 hours to find the problem, and I have a feeling it's something very simple that I'm passing over...
    If you have any questions about the variables or other things, please ask!
    And one last little quick question, is there a way I can restrict the movement of the paddle between two Y values? (i.e not higher than y=10 or lower than y=100)
    Thanks in advance :)

    soundweave wrote:
    I'm not exactly sure how to find out, Eh?
    You wrote this code:
    g.fillRect (10, 10+y, 15, 60+y);Do you understand what fillRect does? If I call fillRect(10, 20, 30, 40) where will that rectangle be drawn? If you don't know how to answer that, I don't see how you could have written that line of code.
    but here's some pictures of what happens ( I put in 0 and 80 as the y values in each picture, and left the code window open so you can see )I don't need to see them.
    Y at 0: [http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701|http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701]
    Y at 80: [http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625|http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625]
    So, given that the first one comes from fillRect(10, 10, 15, 60), (you get where that comes from I hope) and the second comes from fillRect(10, 90, 15, 150) (that too), does that not suggest that something is wrong with the numbers you're passing to fillRect? And since you have read the docs for fillRect and know what it does and what each of its parameters represents (right?), does it not suggest exactly what is wrong with those numbers?

  • New TO JAVA Programming

    Dear Forummembers,
    I am student doing postgraduate studies in IT.i have some queries related to one of my programming staff.i am very much new into Java programming and i am finding it a bit difficult to handle this program.The synopsis of the program is given below -
    You are required to design and code an object-oriented java program to process bookings for a theatre perfomance.
    Your program will read from a data file containing specifications of the performance,including the names of the theatre, the play and its author and the layout of the theatre consisting of the number of seats in each row.
    It will then run a menu driven operation to accept theatre bookings or display the current
    status of seating in the theatre.
    The name of the file containing the details of the performance and the theatre should be
    provided at the command line, eg by running the program with the command:
    java Booking Theatre.txt
    where Theare.txt represents an example of the data file.
    A possible data file is:
    Opera
    U and Me
    Jennifer Aniston
    5 10 10 11 12 13 14
    The data provided is as follows
    Line 1
    Name of the Theatre
    Line 2
    Name of the play being performed
    Line 3
    Name of the author of the play being performed
    Line 4
    A list of the lengths (number of seats) of each row in the theatre, from front to
    back.
    The program must start by reading this file, storing all the appropriate parameters and
    establishing an object to accept bookings for this performance with all details for the theatre
    and performance.
    The program should then start a loop in which a menu is presented to the user, eg:
    Select from the following:
    B - Book seats
    T - Display Theatre bookings
    Q - Quit from the program
    Enter your choice:
    And keep performing selected operations until the user�s selects the quit option, when the
    program should terminate.
    T - Display Theatre bookings
    The Display Theatre Bookings option should display a plan of the theatre. Every available
    seat should be displayed containing its identification, while reserved seats should contain an
    Rows in each theatre are indicated by letters starting from �A� at the front. Seats are
    numbered from left to right starting from 1. A typical seat in the theatre might be designated
    D12, representing seat 12 in row D.
    B - Book seats
    The booking of seats is to offer a number of different options.
    First the customer must be asked how many adjacent seats are
    required. Then start a loop offering a further menu of choices:
    Enter one of the following:
    The first seat of a selected series, eg D12
    A preferred row letter, eg F
    A ? to have the first available sequence selected for you
    A # to see a display of all available seats
    A 0 to cancel your attempt to book seats
    Enter your selection:
    1. If the user enters a seat indentifier such B6, The program should attempt to
    reserve the required seats starting from that seat. For example if 4 seats are
    required from B6, seats B6, B7, B8 and B9 should be reserved for the customer,
    with a message confirming the reservation and specifying the seats reserved..
    Before this booking can take place, some testing is required. Firstly, the row
    letter must be a valid row. Then the seat number must be within the seats in the
    row and such that the 4 seats would not go beyond the end of the row. The
    program must then check that none of the required seats is already reserved.
    If the seats are invalid or already reserved, no reservation should be made and the
    booking menu should be repeated to give the customer a further chance to book
    seats.
    If the reservation is successful, return to the main menu.
    2. The user can also simply enter a row letter, eg B.IN this case, the program should
    first check that the letter is a valid row and then offer the user in turn each
    adjacent block of the required size in the specified row and for each ask whether
    the customer wants to take them. Using the partly booked theatre layout above, if
    the customer wanted 2 seats from row B, the customer should be offered first:
    Seats B5 to B6
    then if the customer does not want them:
    Seats B10 to B11
    and finally
    Seats B11 to B12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the row, then report
    that no further blocks of the required size are available in the row and repeat the
    booking menu.
    3. If the user enters a ? the program should offer the customer every block of seats
    of the required size in the whole theatre. This process should start from the first
    row and proceed back a row at a time. For example, again using the partially
    booked theatre shown above, if the user requested 9 seats, the program should
    offer in turn:
    Seats A1 to A9
    Seats C1 to C9
    Seats C2 to C10
    Seats E3 to E11
    Seats E4 to E12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the whole theatre,
    then report that no further blocks of the required size are available and repeat the
    booking menu.
    4. If the user enters a # the program should display the current status of the seating
    in the theatre, exactly the same as for the T option from the main menu and then
    repeat the booking menu.
    5. If the user enters a 0 (zero), the program should exit from the booking menu back
    to the main menu. If for example the user wanted 9 seats and no block of 9 was
    left in the theatre, he would need to make two separate smaller bookings.
    The program should perform limited data validation in the booking process. If a single
    character other than 0, ? and # is entered, it should be treated as a row letter and then tested
    for falling within the range of valid rows, eg A to H in the example above. Any invalid row
    letters should be rejected.
    If more than one character is entered, the first character should be tested as a valid row letter,
    and the numeric part should be tested for falling within the given row. You are NOT
    required to test for valid numeric input as this would require the use of Exception handling.
    You are provided with a class file:
    Pad.java
    containing methods that can be used for neat alignment of the seat identifiers in the theatre
    plan.
    File Processing
    The file to be read must be opened within the program and if the named file does not exist, a
    FileNotFoundException will be generated. It is desirable that this Exception be caught and
    a corrected file name should be asked for.
    This is not required for this assignment, as Exception handling has not been covered in this
    Unit. It will be acceptable if the method simply throws IOException in its heading.
    The only checking that is required is to make sure that the user does supply a file on the
    command line, containing details of the performance. This can be tested for by checking the
    length of the parameter array args. The array length should be 1. If not, display an error
    message telling the user the correct way to run the program and then terminate the program
    System.exit(0);
    The file should be closed after reading is completed.
    Program Requirements
    You are expected to create at least three classes in developing a solution to this problem.
    There should be an outer driving class, a class to represent the theatre performance and its
    bookings and a class to represent a single row within the theatre.
    You will also need to use arrays at two levels. You will need an array of Rows in the Theatre
    class.
    Each Row object will need an array of seats to keep track of which seats have been reserved.
    Your outer driving class should be called BookingOffice and should be submitted in a file named BookingOffice.java
    Your second, third and any additional classes, should be submitted in separate files, each
    class in a .java file named with the same name as the class
    I am also very sorry to give such a long description.but i mainly want to know how to approach for this program.
    also how to designate each row about it's column while it is being read from the text file, how to store it, how to denote first row as row A(second row as row B and so on) and WHICH CLASS WILL PERFORM WHICH OPERATIONS.
    pls do give a rough guideline about designing each class and it's reponsibilty.
    thanking u and looking forward for your help,
    sincerely
    RK

    yes i do know that........but can u ppl pls mention
    atleast what classes shud i consider and what will be
    the functions of each class?No, sorry. Maybe somebody else will, but in general, this is not a good question for this forum. It's too broad, and the question you're asking is an overall problem solving approach that you should be familiar with at this point.
    These forums are best suited to more specific questions. "How do I approach this homework?" is not something that most people are willing or able to answer in a forum like this.

  • In acrobat 9 pro how do you fill a color in a picture?

    Hello Everyone,
    Does anyone know how to fill a color in a picture using Adobe acrobat 9 Pro. Lets say you have a picture in PDF format, that has a picture of a billboard, and that billboard is not really straight, kinda different shape, how could someone leave it in as a PDF and color the bilboard?
    Any help would be great!

    Actually Graffiti it might be able to be done via 'touchup tool' without creating a new PDF. Assuming of course a photo editor like Photoshop is present.
    To the OP: Acrobat is intended as final destination format and not really suitable for editing (although minor changes can be made with the full Acrobat product). It's always best to do the changes to the original document and then make a new PDF making sure you acknowledge proper version control procedures. Changing the PDF means that you now have a PDF that doesn't match the original document.

  • I'm new to Java, anyone want to lend a hand?

    Please copy my program in to Java and take a look. What I am trying to do is when the button is pressed to buy a Mr Big bar I want the quantity value to rise by one, only it doesn't. I have tried several things to no avail! I may be missing something really easy but if someone could help I would be very grateful.
    many thanks.
    Sorry for the length of it....
    package myprojects.avending;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class AVending
    public AVending()
    AVControl control = new AVControl();
    public static void main(String args[])
    System.out.println("Starting ACME Vending Machine, please stand by...");
    AVending startup = new AVending();
    class AVControl extends Frame
    public AVControl()
    setSize(700, 150);
    setBackground(Color.black);
    setTitle("ACME Vending Machine Control Room");
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    setVisible(true);
    AVCustomer custobj = new AVCustomer(this);
    class AVCustomer extends Frame implements ActionListener
    private JButton ACC;
    public AVCustomer(AVControl avc)
    setSize(150, 350);
    setLayout(new BorderLayout());
    setBackground(Color.black);
    setTitle("Customer Location");
    ACC = new JButton("ACC");
    ACC.setForeground(Color.black);
    ACC.setBackground(Color.white);
    ACC.setEnabled(true);
    ACC.setVisible(true);
    ACC.setBounds(0, 0, 100, 30);
    add(BorderLayout.NORTH, ACC);
    ACC.addActionListener(this);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    setVisible(true);
    AVendingMachine vmachine = new AVendingMachine(this);
    public void actionPerformed(ActionEvent ae)
    ae.getSource();
    if(ae.getSource()==ACC)
    VMachine vm = new VMachine(this);
    public void paint(Graphics g)
    g.setColor(Color.white);
    g.drawString("Vending Machines", 10, 80);
    g.drawString("currently available - 1", 10, 95);
    class VMachine extends Frame implements ActionListener
    private JButton buybut1;
    public int quan;
    private JTextField tf2a;
    public VMachine(AVCustomer c)
    setSize(200, 400);
    setLayout(new BorderLayout());
    setBackground(Color.red);
    setTitle("Vending Machine");
    Panel panel1 = new Panel();
    panel1.setBackground(Color.black);
    panel1.setLayout(new FlowLayout());
    add(BorderLayout.NORTH, panel1);
    JTextField tf1 = new JTextField("Air Canada Center", 12);
    tf1.setHorizontalAlignment(JTextField.CENTER);
    tf1.setEditable(false);
    panel1.add(tf1);
    Panel panel2 = new Panel();
    panel2.setBackground(Color.red);
    panel2.setLayout(new GridLayout(4,3));
    add(panel2);
    quan = 0;
    Panel panel3 = new Panel(new FlowLayout());
    panel3.setBackground(Color.red);
    add(panel3);
    JTextField tf2 = new JTextField("Mr Big", 6);
    JTextField tf2a = new JTextField(""+quan);
    tf2.setHorizontalAlignment(JTextField.CENTER);
    tf2.setEditable(false);
    tf2a.setHorizontalAlignment(JTextField.CENTER);
    tf2a.setEditable(false);
    panel3.add(tf2);
    panel3.add(tf2a);
    buybut1 = new JButton("Buy");
    buybut1.setForeground(Color.black);
    buybut1.setEnabled(true);
    buybut1.setVisible(true);
    buybut1.setBounds(0, 0, 100, 30);
    panel3.add(buybut1);
    buybut1.addActionListener(this);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    setVisible(true);
    public void actionPerformed(ActionEvent ae)
    if(ae.getSource()==buybut1)
    System.out.println("Button works ok");
    quan = quan + 1;
    tf2a.setText(""+quan);
    }

    first, the code you provided does not compile - there was no AVendingMachine class...I assumed you meant VMachine
    once that is solved you get a NullPointerException when you press the button, which was caused by the fact that you declared the text field inside the constructor, when you stop declaring it, and just initialize it everything works fine..
    also, you might want to change your JTextFields to JLabels -- they will look nicer

  • How to put a startup picture in a java program?

    Hi there,
    I'm extremely new in Java programming and have a very weak knowledge in C programming. I managed to download a Java source file from the internet which I need to use for my school's project. I was wondering would it be possible for me to put a start up picture or video clip before the program runs? And if so, how do I go about doing it? Thanks in advance.
    LostInJava

    Requires the latest Java version, Java 6.And there are fairly simple ways to program your own splash screens in earlier versions.

  • When exporting out of lightroom the color of my picture channges significantly

    I use windows 8 and tried exporting out of lightroom through firefox and this did not help either

    Hi Shmuglak.  Thank you for the information.  I tried those things but did not work.    I just got windows 8 and just downloaded photoshop CC and Lightroom from the cloud.   My settings in Lightroom under preferences are :   Under jpeg preview it is checked on fast load data.   Under external editing the color space is prophoto.   Under additional external editor it is set to preset (Custom).  Under Default Develop Settings the only thing checked is apply auto mix when first converting to BW.   Under export module:   Location:   set to same as original folder and no check mark on add to catalog.   Under Post Processing I have tried do nothing and tried firefox.    
    It is funny that when I export a picture from lightroom using firefox that picture  pops for preview and the picture looks fine but then when I go to my email and try to email that same picture and use send with a file attachment the picture looks aweful on my desktop but when looking at it on the ipad or iphone the picture looks fine.
    Any other suggestions would be great
    thank you
    Date: Thu, 12 Dec 2013 00:56:36 -0800
    From: [email protected]
    To: [email protected]
    Subject: when exporting out of lightroom the color of my picture channges significantly
        Re: when exporting out of lightroom the color of my picture channges significantly
        created by shmuglak in Photoshop Lightroom - View the full discussion
    I don't know if this is your case but I have a similar problem (and has been helped out by some kind soul on this forum). The change of color may happen if you are re-importing the exported pictures into the Lightroom catalog. If this is what you are doing, some import presets may be applied and this may cause the color change. I'm talking about this setting, sheck if it is enabled. If it is, disable it and see if it helps.
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5923235#5923235
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5923235#5923235
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5923235#5923235. In the Actions box on the right, click the Stop Email Notifications link.
               Start a new discussion in Photoshop Lightroom at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

  • New Release: Java ES 5 Update 1 - **Correction**

    In my entry on Sep 5, 2007 7:34 AM with the topic of "New Release: Java ES 5 Update 1", I incorrectly stated that Sun Application Server 9.1 was certified with Java ES 5 Update 1. It is not. The fully certified and supported web containers are listed in the Java ES 5 Update 1 Release Notes. For now, it is not supported by Java ES 5 Update 1 component products, but future releases of Sun middleware products will, so hang tight. I do apologize for any inconvenience. The official documentation at docs.sun.com should always be considered the source for what is supported and what is not.
    Here is a corrected entry...
    In case you haven't noticed there is a new version of the Java Enterprise System that was posted to the Sun Download site on Friday September 1, 2007. The new release is Java ES 5 Update 1. Here is the main Java ES download page.
    Here are the versions of the individual products that are in Java ES 5 Update 1:
    * Directory Server 6.2 EE
    * Directory Proxy Server 6.2
    * Application Server 8.2 Patch 2
    * Service Registry 3.1 Update 1
    * Access Manager 7.1
    * Portal Server 7.1 Update 2
    * Message Queue 3.7 Update 2
    * Web Server 7.0 Update 1
    * Web Proxy Server 4.0.5
    This release is mainly a maintenance release, with lots of bug fixes. But there are a few new and interesting features included also.
    One interesting feature is the inclusion of Service Tags. Service Tags are digital identifiers that can be embedded in software or firmware and that holds a small amount of product information. The Sun Connection Registration Manager discovers service tags and registers the products and allows you to view and manage your registered products online. You can check out Sun Connection Inventory Channel here. Not all of the Sun Java System components are Service Tag-enabled just yet, but a lot of them are. Here is the list of the components that are Service Tag-enabled:
    * Directory Server 6.2 EE
    * Application Server 8.2 Patch 2
    * Access Manager 7.1
    * Portal Server 7.1 Update 2
    * Web Server 7.0 Update 1
    * Monitoring/JMX framework

    To install Sun Java Stutio 5 update 1 under SuSE
    LInux (tested with SuSE 9.0 Professional, but should
    work with other versions) simply create a text file
    in /etc named suse-release with the follwoing
    content: Sun Java Desktop System 2003
    Now you will be able to install Sun One Stutio 5
    update 1 under SuSE.Did not work - still got (-is:log log.txt):
    Executing launch script command: "/usr/lib/java/bin/java" -cp "/tmp/isjtPgeKd/Verify.jar" "Verify" java.vendor java.version in working directory /root/install/.
    Output from the launch script execution
    StdOut:
    1739021872
    Sun Microsystems Inc.
    1.4.2_04
    ErrOut:
    Found matching JVM at /usr/lib/java/
    Matching JVM home is /usr/lib/java/
    Matching JVM file is /tmp/isjGbTC86
    Executing launch script command: "/usr/lib/java//bin/java" -cp "/tmp/isjPpa0A0/s1s5u1se-linux-en.jar" -Dtemp.dir="/tmp" -Dis.jvm.home="/usr/lib/java/" -Dis.jvm.temp="0" -Dis.media.home="/tmp/isjPpa0A0/s1s5u1se-linux-en.jar" -Dis.launcher.file="/root/install/./s1s5u1se-linux-en.bin" -Dis.jvm.file="/tmp/isjGbTC86" -Dis.external.home="/root/install/." run in working directory /root/install/.
    Output from the launch script execution
    StdOut:
    ErrOut:
    The wizard cannot continue because of the following error: could not load wizard specified in /wizard.inf (104)
    Any help would be greatly appreciated, thnx

  • New to Java and trying to make a game

    I'm really new to Java so please try not to roll over laughing at the following code. At the moment, as you can hopefully pick up from the code, i'm trying to get a shape(Polygon) to respond to keyboard events and i'm trying to make the object primarily respond to the cursor keys and to move the Polygon in the corresponding directions of the cursors. I'm stuck and i think i have initialised everything but i can't get the shape to move. I'm pretty sure i'm missing required code in the paint method.
    <code>
    import java.awt.*;
    import java.awt.Event.*;
    import java.applet.*;
    import java.io.*;
    public class PlodInvaders extends Applet implements Runnable {
    Point start, end, fire, shield, target;
    int co_x, x, y;
    int co_y;
    int current_x, current_y;
    char current_key;
    Font theFont;
    Thread th;
    Image ship;
    Polygon p;
    public void init() {
    setBackground(Color.black);
    // mouse co-oridnates
    co_x = this.size().width + 5;
    co_y = this.size().height + 5;
    theFont= new Font("Courier", Font.BOLD, 24);
    current_x = 150;
    current_y = 100;
    public void start() {
    th = new Thread(this);
    th.start();
    public boolean KeyDown(Event evt, int key) {
    switch(key) {
    case Event.LEFT: current_x = current_x - 10; break;
    case Event.RIGHT: current_x = current_x +10; break;
    case Event.UP: current_y = current_y + 10; break;
    case Event.DOWN: current_y = current_y - 10; break;
    default: current_key = (char) key;
    start = new Point(x, y);
    repaint();
    return true;
    public boolean MouseDown(Event evt, int x, int y) {
    fire = new Point(x, y);
    return true;
    public boolean MouseUp(Event evt, int x, int y) {
    target = new Point(x, y);
    repaint();
    return true;
    public void run() {
    public void paint(Graphics g){
    Polygon p = new Polygon();
    g.setColor(Color.white);
    p.addPoint(20,20);
    p.addPoint(50,25);
    p.addPoint(50,50);
    p.addPoint(25,50);
    p.addPoint(20,20);
    g.fillPolygon(p);
    </code>

    this is not prefect and it is not a applet, but it will make you start. you can email if you have any qeustions
    import java.awt.*;
    import java.awt.event.*;
    public class MoveP extends Frame implements KeyListener
         Polygon po = new Polygon();
            int ix=0;
         int iy=0;
    public MoveP()  
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         addKeyListener(this);
         setSize(300,372);
         po.addPoint(20,20);
         po.addPoint(50,25);
         po.addPoint(50,50);
         po.addPoint(25,50);
         po.addPoint(20,20);
         setVisible(true); 
    public void paint(Graphics g)
         g.setColor(Color.black);
         for (int i=0; i < po.npoints; i++)
              po.xpoints[i]+=ix;
              po.ypoints[i]+=iy;
         g.fillPolygon(po);
    public void keyTyped(KeyEvent e)
    public void keyPressed(KeyEvent e)
         ix = 0;
         iy = 0;
         int k = e.getKeyCode();
         if (k == 40) iy++;
         if (k == 38) iy--;
         if (k == 39) ix++;
         if (k == 37) ix--;
         repaint();
    public void keyReleased(KeyEvent e)
    public static void main (String[] args)
         new MoveP();
          Noah

  • Hello, I am new to java and I am trying to something cool

    Hello I am new to Java and I am trying to do something cool. I have written some code and it compiles nicely. Basically what I am trying to do is use ActionListeners with JTextArea to change the size of a rectangle thing.
    Here is my code. The problem is that when I push the submit button nothing happens. Any help you could give would be greatly appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    class SecondGate extends JFrame implements ActionListener {
         float sxd = 190f;
         float dps = 190f;
         JTextArea Long = new JTextArea(1,3);
         JTextArea Short = new JTextArea(1,3);
         JLabel one = new JLabel("width");
         JLabel two = new JLabel ("Height");
         JButton Submit = new JButton("Submit");
    public SecondGate() {
    super("Draw a Square");
    setSize(500, 500);
         Submit.addActionListener(this);
         setLayout(new BorderLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         String Width = Float.toString(sxd);
         String Height = Float.toString(dps);
         Rect sf = new Rect(Width, Height);
         JPanel pane = new JPanel();
         pane.add(one);
         pane.add(Long);
         pane.add(two);
         pane.add(Short);
         pane.add(Submit);
         add(pane, BorderLayout.EAST);
         add(sf,BorderLayout.CENTER);
    setVisible(true);
         public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == Submit) {
              sxd = Float.parseFloat(Long.getText());
              dps = Float.parseFloat(Short.getText());
         repaint();
         public static void main(String[] arguments) {
    SecondGate frame = new SecondGate();
    class Rect extends JPanel {
         String Width;
         String Height;
    public Rect(String Width, String Height) {
    super();
    this.Width = Width;
    this.Height = Height;
    public void paintComponent(Graphics comp) {
    super.paintComponent(comp);
    Graphics2D comp2D = (Graphics2D)comp;
    comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         BasicStroke pen = new BasicStroke(5F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
    comp2D.setStroke(pen);
         comp2D.setColor(Color.blue);
         BasicStroke pen2 = new BasicStroke();
    comp2D.setStroke(pen2);
    Ellipse2D.Float e1 = new Ellipse2D.Float(235, 140, Float.valueOf(Width), Float.valueOf(Height));
    comp2D.fill(e1);
         GeneralPath fl = new GeneralPath();
         fl.moveTo(100F, 90F);
         fl.lineTo((Float.valueOf(Width) + 100F),90F);
         fl.lineTo((Float.valueOf(Width) + 100F),(Float.valueOf(Height) + 90F));
         fl.lineTo(100F,(Float.valueOf(Height) + 90F));
         fl.closePath();
         comp2D.fill(fl);
         }

    I got it to work. You were right about the method and references. Thank you
    Here is the working code for anyone who is interested in how to do this.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    class SecondGate extends JFrame implements ActionListener {
    float sxd = 190f;
    float dps = 190f;
    JTextArea Long = new JTextArea(1,3);
    JTextArea Short = new JTextArea(1,3);
    JLabel one = new JLabel("width");
    JLabel two = new JLabel ("Height");
    JButton Submit = new JButton("Submit");
    String Width = Float.toString(sxd);
    String Height = Float.toString(dps);
    Rect sf = new Rect(Width, Height);
         public SecondGate() {
              super("Draw a Square");
              setSize(500, 500);
              Submit.addActionListener(this);
              setLayout(new BorderLayout());
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel pane = new JPanel();
              pane.add(one);
              pane.add(Long);
              pane.add(two);
              pane.add(Short);
              pane.add(Submit);
              add(pane, BorderLayout.EAST);
              add(sf,BorderLayout.CENTER);
              setVisible(true);
         public void actionPerformed(ActionEvent evt) {
              Object source = evt.getSource();
              if (source == Submit) {
              String Width = Long.getText();
              String Height = Short.getText();          
              sf.Width(Width);
              sf.Height(Height);
                   repaint();
         public static void main(String[] arguments) {
              SecondGate frame = new SecondGate();
         class Rect extends JPanel {
              String Width;
              String Height;
         public Rect(String Width, String Height) {
              super();
              this.Width = Width;
              this.Height = Height;
         String Width (String Width){
              this.Width = Width;
              return this.Width;
         String Height (String Height) {
              this.Height = Height;
              return Height;
         public void paintComponent(Graphics comp) {
              super.paintComponent(comp);
              Graphics2D comp2D = (Graphics2D)comp;
              comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              BasicStroke pen = new BasicStroke(5F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
              comp2D.setStroke(pen);
              comp2D.setColor(Color.blue);
              BasicStroke pen2 = new BasicStroke();
              comp2D.setStroke(pen2);
              Ellipse2D.Float e1 = new Ellipse2D.Float(235, 140, Float.valueOf(Width), Float.valueOf(Height));
              comp2D.fill(e1);
              GeneralPath fl = new GeneralPath();
              fl.moveTo(100F, 90F);
              fl.lineTo((Float.valueOf(Width) + 100F),90F);
              fl.lineTo((Float.valueOf(Width) + 100F),(Float.valueOf(Height) + 90F));
              fl.lineTo(100F,(Float.valueOf(Height) + 90F));
              fl.closePath();
              comp2D.fill(fl);
              }

  • How do I change the color scheme on my new Iphone 4s

    I accidentally changed the color scheme of the new 4s I purchase, I mean everything inluding the look of apps and thier colors.
    It makes my pictures I take look all screwed up...they all look almost Sepia and like an exposed role of film.
    How do I change the color scheme back to the original settings?

    You seem to be referring to more than the background wallpaper for the home screen.  There are no "color scheme" settings in the phone - you may have activated white on black used for the visually impaired.
    Settings > General > Accessibility > White on Black >OFF

  • How can I open help file (HTML or .chm) from Java Web Start (new to JAVA)

    Hi All,
    Im trying to open the help file of my application.
    When trying to access the help file from the GUI (pressing F1 for launching the help file), I'm geting the an error, something like:
    "Can't show help URL: jar:file:C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart\RMjar-name!/com/resources/helpFiles/MyHelpFile.html"
    It seems that the file which is packed in a jar, was downloaded to the Java Web Start cache directory:
    C:\Documents and Settings\%USER%\Application Data\Sun\Java\Deployment\javaws\cache\http\Dlocalhost\P7001\DMwebstart
    The code which is activated when launching the help file is:
    try
                ResourceBundle resourceBundle = DoubleResourceBundle.getBundle("Resource", "ResourceImpl");
                RuntimeUtil.launchFile(new File(resourceBundle.getString("help.file")));
            } catch (IOException e)
                // TODO Auto-generated catch block
                e.printStackTrace();
            }where the property "help.file" is in some property file in the resource bundle named "Resource", and looks like this :
    help.file="com/trax/docs/help/global/MyHelpFile.html"
    The function "RuntimeUtil.launchFile" knows how to launch any file in its default application, and indeed it does launches the html, when giving it an absolute path to the file on my PC, as "C:\Helpfiles\MyHelpFile.html" as such:
    RuntimeUtil.launchFile("C:\Helpfiles\MyHelpFile.html");My question is :
    The application is going to be deployed on a Customer PC. How can I access the html file from the code, with a relative path and not its absolute path on the customer pc, which I can't know?
    I found these restrictions regarding web start:
    (copied from "http://rachel.sourceforge.net/"):
    *Rule 1: Java Archives only. No loose files.* All your resources have to be packaged in Java Archives (jar) if you want to have
    them delivered to the user's machine and kept up-to-date automatically by Java Web Start.
    *Rule 2: No file paths.* You can't use absolute or relative file paths to locate your
    jars holding your resources (e.g. <code>jar:file:///c:/java/jws/.cache/resources.jar</code>).
    Absolute file paths won't work because you never know where Java Web Start
    will put your jar on the user's machine. Relative file paths won't work because Java Web Start
    mangles the names of your jars (e.g. <code>venus.jar</code> becomes <code>RMvenus.jar</code>)
    and every JNLP client implementation has the right to mangle your names
    in a different way and you, therefore, can't predict the name with
    which your jar will be rechristend and end up on the user's machine in
    the application cache.Seems complex or impossible, to perform a simple task like opening a file.
    Please advise (I'm new to Java and Web Start).
    BTW, I'm working with IntelliJ IDEA 5.0.
    Thanks,
    Zedik.
    {font:Tahoma}{size:26pt}
    {size}{font}

    the follwing method i have used to open html file ...
    so to access html file i am shipping resources folder with jar file ..
    private void openHtmlPages(String pageName) {
         String cmd[] = new String[2];
         String browser = null;
         File file = null;
         if(System.getProperty("os.name").indexOf("Linux")>-1) {
              file = new File("/usr/bin/mozilla");
              if(!file.exists() ) {
              }else     {
                   browser = "mozilla";
         }else {
              browser = "<path of iexplore>";
         cmd[0] = browser;
         File files = new File("");
         String metaData = "/resources/Help/Files/"+pageName+".html"; // folder inside jar file
         java.net.URL url = this.getClass().getResource(metaData);
         String fileName = url.getFile();
         fileName = fileName.replaceAll("file:/","");
         fileName = fileName.replaceAll("%2520"," ");
         fileName = fileName.replaceAll("%20"," ");
         fileName = fileName.replaceAll("jarfilename.jar!"," ").trim();
         cmd[1] = fileName;     
         try{
              Process p = Runtime.getRuntime().exec(cmd);
         }catch(java.io.IOException io){
                   //Ignore
    can anyone give me the solution..???
    Regards
    Ganesan S

  • What is new in Java syntaxes in new Java versions?

    What is new in Java syntaxes in new Java versions?
    What about this sentenses
    1. for (int c:data), where data is array of integer
    2. ArrayList<Object> () ...
    3. Class<?>...
    I can't find this syntaxes in my books and documentation...
    And what Java version is latest?

    dont crosspost
    Edited by language police

  • What's new in Java 4

    Anybody can quickly explain the things are added in Java 4 newly.
    Thnx in advance.

    Nothing's new in Java 4 because there is no Java 4.
    Maybe you mean Java 5?
    Or maybe you mean Java 1.4?
    In either case, either the download page for that version, or the installation, should have release notes that answer your question.
    In fact, here they are for Java 5:
    http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html

Maybe you are looking for

  • Erro tablespace no GRC, notas paradas após correção

    Olá pessoal, Hoje de madrugada houve um problema de tablespace no GRC e todas as notas emitidas durante o período, ficaram paradas com Status 01 (Received from feeder system). Após a correção, as novas notas emitidas foram processadas normalmente por

  • Deployment aborted while deploying a webdynpro application

    Hi SDNers, While deploying a webdynpro application deployment aborted and shown the following error. Aug 8, 2006 4:51:38 PM /userOut/deploy (com.sap.ide.eclipse.sdm.threading.DeployThreadManager) [Thread[Deploy Thread,5,main]] ERROR: [010]Deployment

  • Installing photoshop cs4 on windows 8

    My computer crashed yesterday (old Windows Vista). I had Photoshop CS4 loaded which was an upgrade from Elements. I downloaded it. I have the key number for cs4 and elements. It downloaded ok but will not open .This is on a new Windows 8 system. Any

  • Use of Extract datasets

    Hello, Having seen various instances of the EXTRACT command in some legacy code I've got around to trying out this command but I can't get it to work properly. Here's some condensed test code I've put together: TABLES: VBAK, VBAP. FIELD-GROUPS: HEADE

  • How to read Blueprint Structure using ABAP

    Hello All, We are creating a report for which we need to read the projects blueprint structures (from ABAP). Anyone any ideas what tables to read from, or what bapi calls we can make for this? Thanks, Jurjen