How to display two different parts of one image in two windows?

hi everyone:) i need to display two different parts of one image in two windows. i have problem with displaying :/ because after creating windows there aren't any images :( i supose my initialization code of creating windows is incomplete, maybe i miss something or maybe there is some inconistency. graphics in java is not my strong position. complete code is below. can anybody help me?
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.util.*;
class ImgFrame extends JFrame
       private BufferedImage img;
       ImgFrame(BufferedImage B_Img, int x, int y, int w, int h)
               super("d");
               img=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
               img=B_Img.getSubimage(x, y, w, h);
       }//end ImgFrame construction
       public void paint(Graphics g)
               Graphics2D g2D = (Graphics2D)g;
               g.drawImage(img, 8, 8, null);
       }//end paint method
       public Dimension getPrefferedSize()
               if(img==null)
                       return(new Dimension(100,100));
               else
                       return(new Dimension(img.getWidth(null),img.getHeight(null)));
       }//end of GetPrefferedSize method
}//end ImgFrame class
public class TestGraph2D_03 extends Component
       static BufferedImage IMG;
       public static void Load()
               try
                       IMG=ImageIO.read(new File("c:/test.bmp"));
               catch(IOException ioe)
                       System.out.println("an exception: "+ioe);
               }//end try catch
       }//end TestGraph2D_03 construction
       public static void main(String[] args)
               Load();
               ImgFrame F1 = new ImgFrame(IMG, 0, 0, 8, 8);
               ImgFrame F2 = new ImgFrame(IMG, 8, 8, 8, 8);
               F1.addWindowListener(new WindowAdapter()
                       public void windowClosing(WindowEvent e)
                               System.exit(0);
               F1.pack();
               F1.setVisible(true);
               F2.addWindowListener(new WindowAdapter()
                       public void windowClosing(WindowEvent e)
                               System.exit(0);
               F2.pack();
               F2.setVisible(true);
       }//end of main method in TestGraph2D_01 class
}//end of TestGraph2D_03 class

Never override the paint(...) method of a Swing component.
If you have a sub image then add the image to a JLabel and add the label to the GUI. No need for custom painting.

Similar Messages

  • Link graphic frames to show different parts of one image

    Hi all,
    I want to make a sort of broken-up canvas effect with a photo, and thought I could do this with frames?
    I want to create a grid of rectangles (alternating so you only see the white space separating them), and the triangles all have a part of the overall picture in it. When you see the whole grid, you see the whole picture. Can I do this in InDesign?
    Thanks!

    1. Make the grid of rectangles, select all
    2. Press Cmd+8 (you get a compound path)
    3. Select the compound path and place the image into it
    You can direct select the image in the compound path, for any positioning.

  • How to display an double type variable's value with two decimals?

    for exmple, what I do is:
    double a = 1.5;
    system.out.println(a);
    I see 1.5 in the screen, however, I wanna display 1.50. how to do that?
    I know how to round an double value, say, 1.555 to 1.56, but I can't find how to display a double value from one decimal to two decimal, any help will be very appreciate!

    for exmple, what I do is:
    double a = 1.5;
    system.out.println(a);
    I see 1.5 in the screen, however, I wanna display
    1.50. how to do that?
    you could convert the double to a string and then append a zero to the end
    String str = Double.toString(a);
    str += "0";
    System.out.println(a);

  • I would like the share an iTunes library between two different accounts on one Mac. How do I do this?

    iTunes no longer works properly (aka at all) while using one of the user accounts set up on my iMac. It does, however, work when logging in under another user account on the same iMac. (if any of you can help me solve this issue that would be perfect). If there is no solution can anyone help with my request to share an iTunes library between two different accounts on one Mac. How do I do this?

    jc_hering wrote:
    that works for anything he purchases after he creates the new account.  What about his current music that currently resides in my itunes library?  How can I get his current music out of my library into his new account/library??  Thanks..
    Copy it to his computer into his iTunes library and authorize his computer with the iTunes account used to purchase them..
    You cannot tranfser items from one iTunes account to another. Purchased items remain part of the iTunes account is was purchased with.
    iTunes account - used to purchase items
    iTunes library - where purchases (and CD RIPs) go on the computer

  • How to display different parts of an image

    hi,
    I need to display different parts of an image at specific situations.
    for example, a dice. there is only one image which includes different sides of the dice. and I wanna add
    to my panel one side if one comes, two side if two comes... I mean if one comes then we will display
    from 10 px to 80 px width and from 10 px to 80 px height of the dice image.
    is there any way to obtain this in java?
    thanks...

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.util.Random;
    import javax.swing.*;
    public class ImageClipping extends JPanel {
        BufferedImage image;
        Rectangle clip;
        final int ROWS = 3;
        final int COLS = 3;
        public ImageClipping() {
            // Make an image we can clip.
            Dimension d = getPreferredSize();
            int type = BufferedImage.TYPE_INT_RGB;
            image = new BufferedImage(d.width, d.height, type);
            Graphics2D g2 = image.createGraphics();
            g2.setBackground(getBackground());
            g2.clearRect(0, 0, d.width, d.height);
            Font font = g2.getFont().deriveFont(36f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            float sh = lm.getAscent() + lm.getDescent();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            for(int j = 0; j < ROWS; j++) {
                for(int k = 0; k < COLS; k++) {
                    String s = String.valueOf(j*COLS + k+1);
                    float sw = (float)font.getStringBounds(s, frc).getWidth();
                    float sx = k*xInc + (xInc - sw)/2;
                    float sy = j*yInc + (yInc + sh)/2 - lm.getDescent();
                    g2.setPaint(Color.red);
                    g2.drawString(s, sx, sy);
                    g2.setPaint(Color.blue);
                    g2.drawRect(k*xInc, j*yInc, xInc-1, yInc-1);
            g2.dispose();
            clip = new Rectangle(xInc, yInc);
            // Inspect image.
            ImageIcon icon = new ImageIcon(image);
            JOptionPane.showMessageDialog(null, icon, "", -1);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            Shape origClip = g2.getClip();
            //g2.setPaint(Color.red);
            //g2.draw(clip);
            // Draw clipped image at:
            int x = 100;
            int y = 100;
            // Mark location.
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(x-2,y-2,4,4));
            // Position the image.
            g2.translate(x-clip.x, y-clip.y);
            // Clip it and draw.
            g2.setClip(clip);
            g2.drawImage(image,0,0,this);
            // Reverse the changes to the graphics context.
            g2.setClip(origClip);
            g2.translate(clip.x-x, clip.y-y);
        public Dimension getPreferredSize() {
            return new Dimension(400,400);
        public static void main(String[] args) {
            ImageClipping test = new ImageClipping();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.pack();
            f.setLocation(50,50);
            f.setVisible(true);
            test.start();
        private void start() {
            Thread thread = new Thread(runner);
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        private Runnable runner = new Runnable() {
            Random seed = new Random();
            Dimension d = getPreferredSize();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            public void run() {
                do {
                    try {
                        Thread.sleep(3000);
                    } catch(InterruptedException e) {
                        break;
                    int row = seed.nextInt(ROWS);
                    int col = seed.nextInt(COLS);
                    int x = col*xInc;
                    int y = row*yInc;
                    int n = row*COLS + col+1;
                    System.out.printf("row = %d  col = %d  n = %d%n",
                                       row, col, n);
                    clip.setLocation(x,y);
                    repaint();
                } while(isVisible());
    }

  • How do you set up two different ipads on one computer ?

    I purchased a new ipad for my wife and want to get her started but we both use one imac as our desktop system.  How do you set up two different uses on one computer.
    Thanks,
    Dave

    Other options not covered in the article:
    1) You can plug both in under the same computer username and same iTunes Apple ID and give each device it's own name. You should be able to manage them as separate devices with different media, apps and screen layouts. All of your media would be in a common pool, though.
    2) Under one computer username, you can login and logout of two different iTunes Apple IDs. This option is cleaner with two computer usernames but it can be done with one.

  • I recently deleted many duplicate files. In the midst of it my Itunes songs are not in Itunes. They are in two different folders. One under 'Music' in my ID. And two under a MyMusic file in Documents. How do I know which one to import?

    I recently deleted many duplicate files. In the midst of it my Itunes songs are not in Itunes. They are in two different folders. One under 'Music' in my ID. And two under a MyMusic file in Documents. How do I know which one to import?

    Thanks, this is not an ideal answer but probably the most sensible one in my case.
    I will try it unless someone has a better suggestion, but I'll wait a bit as it will take me a few days anyway (I had actually tried to create a new smaller playlist or download by album, but at this stage the music app is not letting me queue a list of songs for download - I think I will have to disable and re-enable iTunes match which will probably delete all the songs).
    I have to say I am not very impressed with Apple here - having an online backup of all your data and beeing able to restore it to a new device easily was a strong selling point of iCloud. For music, they are Definitly not delivering at the stage.

  • How can i sync two different ipods to one computer

    How can i sync two different ipods to one computer

    How to use multiple iPods, iPads, or iPhones with one computer

  • How to sort two different hierarchies in one dimension

    Does anyone know of a way to sort two different hierarchies in one dimension and still make drilling work correctly? We have two hierarchies in our item dimension; one called category and the other origin. Simplified, it looks like this:
    CATEGORY
    Hardware (100)
    ..PCs (100.100)
    ....PC 1
    ....PC 2
    ....PC 3
    ..Monitors (100.200)
    ....Monitor 1
    ....Monitor 2
    ....Monitor 3
    Software (200)
    ..Big (200.100)
    ....ERP package
    ....CRM package
    ..Small (200.200)
    ....Solitaire
    ....Mine Sweeper
    ORIGIN
    Vendor A (10)
    ..Site A1 (10.10)
    ....ERP package
    ..Site A2 (10.20)
    ....PC 1
    ....Monitor 3
    Vendor B (20)
    ..Site B1 (20.10)
    ....PC 2
    ....PC 3
    ....Monitor 1
    ....Monitor 2
    ....Solitaire
    ....Mine Sweeper
    ..Site B2 (20.20)
    ....CRM package
    We have numeric codes at each level above item which I represents the sort order (the number in parentheses at each level), and the items themselves should be sorted according to item number. I have implemented this (level code/item number) as an attribute in AWM making this the default sort order. However, as item is the lowest level in each hierarchy, I have only been able to list the items under the correct level in one hierarchy. As soon as I drill using the other hierarchy, the levels above item are sorted correctly, but the items appear at very odd places...
    The AWM documentation states that if default order is not selected on any attribute, hierarchies are sorted in the order they are created. Is there a way to control this order?
    Any input will be greatly appreciated!

    Hi,
    thank you for your answer. Yes, now I also find the class CL_SALV_WD_MULTI_CELL_EDITOR which could be used to set different UIE in one cell. But it is quite limited, just the following UIE could be used
    - LinkToAction 
    - LinkToURL    
    - FileDownload 
    - Button       
    - ToggleButton 
    best regards,
    Wenwen

  • How can I use two differant iphones on one itunes

    I can i use two differant iphones on one itunes, and keep the content seperate?

    You can sync as many iphones/ipod/ipads as you like to one computer.
    Each is different and is recognized as such

  • Generally when creating a Word file from either a Mac or Win7 pc and opening it on two different machines (either one first) it always prompts that the file is open and will be opened as read only. However opening a CSS file does not prompt that it is alr

    Generally when creating a Word file from either a Mac or Win7 pc and opening it on two different machines (either one first) it always prompts that the file is open and will be opened as read only.
    However opening a CSS file does not prompt that it is already open on or from any machine which is causing code edits to be lost.
    What we found from out testing:
    - The file can be saved from one user to the server and WILL NOT PROMPT on other machines until the saving machine has the Dreamweaver program closed completely
    - The file can be closed and  Dreamweaver minimised to the launch bar but it still will not register on other machines that it has been changed.
    - Also, until the  Dreamweaver program is closed on the machines, it will continue to open it's saved version of the file. 
    Example Scenario:
    - User 1 opens test.css (which is 2000 lines) and adds some code to the end of the file to bring it up to 2500 lines
    - Meanwhile User 2 opens test.css as well (opens as 2000 lines as User 1’s edits have not yet been saved) and adds in code to bring it to 2300 lines
    - User 1 saves his file and closes it - but  Dreamweaver is still open.
    - User 2 also saves his file and leaves  Dreamweaver  open.
    - The server will report the size and last edit of the file the same as User 2 as he was the last person to save it (and if you open from the Win7 Machine it will show as User 2’s 2300 line version)
    - If User 1 then open's the file again (from either the 'recent' in Dreamweaver OR clicking on the file directly in Finder...which version opens.... The version that User 1 saved! Not the true version on the server, but the version that User 1 edited and saved with 2500 lines in it.
    - Same for User 2, he will open 'his' version with 2300 lines in.
    Other information:
    - Files are opened directly from the server
    - Sometimes the users will save incrementally and re-open
    - Most of the time users will save incrementally and keep the files open
    - The users will never not save incrementally and just save when closing the file once finished
    - The users are usually working on the files all day
    - It is always the bottom lines of code that are lost. It could be a case of the two versions being mixed up and cutting off the newly added lines based on the line count (possibly).
    It is as if Dreamweaver is holding a cache of the version locally and then only properly looking back to the server when it has been completely closed. It is very difficult to see how the server is causing such an impact on these files, there are very few logs which are giving any indication to the root cause of the problems.
    Anyone know if this is a known issue?
    Is there a way that there can be a featured implemented on the server that doesn't allow another user to open a file if it is already open on another machine?
    Thanks

    Your server file handling has nothing, and really nothing to do with Adobe software. If files don't get locked for (over-)writing and/or lose connection to the program opening them, then your server is misconfigured. It's as plain and simple and that. Anything from "known file types"/ file associations not being set correctly, MIME types being botched, crooked user privileges and file permissions, missing Mac server extensions, delayed file writing on the server, generic network timeout issues and what have you. Either way, you have written a longwinded post with no real value since you haven't bothered to provide any proper technical info, most notably about the alleged server. Either way, the only way you can "fix" it is by straightening out your server and network configuration, not some magic switch in Adobe's software.
    Mylenium

  • HT1660 I have two iTunes libraries on two different pc's (one windows and one Mac).  Can I consolidate these on an external hard drive?

    I have two iTunes libraries on two different pc's (one windows and one Mac).  Can I consolidate these on an external hard drive?

    I'm sorry I just saw the last post. I had two users on my hard drive, one for me and one for my daughter, but I am not sure what you mean by partioning my external????? I have heard the term before, but don't know how to do it. I am having serious crashing issues with this computer and believe I really need to do a clean install. I just want to make sure everything for both ipods is safe (is???? I think so, everything is......I hate when the English language does this to me!)

  • Combining two different programs on one plate form

    I have two different programs(calaender and addressbook)in two different classes (Each one has a "main").How do i bring them together on a single plateform so that clicking one button will run one of them and clicking other will run the other.
    Could some body please help me?
    Thanks.

    Hi,
    There is a loadClass method in Class. You can use this with reflection.
    You can also write a customised ClassLoader

  • How to display text on last but one page in SAPSCRIPTS

    how to display text on last but one page in SAPSCRIPTS

    u have create one Foooter window , this has to be called in  only One Page.So hardcode /assign this window to only one PAGE number.
    regards
    Prabhu

  • Is there a way to have two different iTunes for two different iPhones on one Windows User account?

    Using Windows 7, iphone 4.
    I've read as many threads on these forums and as many kb's as I could find, but I sttill can't figure it out. I have 2 iPhones. Let's call them, "wife" and "hubby". I want to have two separate iTunes, one for each of the phones. Hubby is the Windoows User. I don't want to set up a different Windows User for wife.
    Hubby was the original iPhone. When I plug it in, iTunes recognized it has Hubby's iPhone. Then I unplug Hubby and close iTunes. I plug in Wife but iTunes stll comes up with Hubby under Devices and syncs Hubby's iTunes to Wife's iphone.
    I've tried using the shift key when I open iTunes to set up two separate .itl files to no avail.
    Is there a way to have two different iTunes for two different iPhones on one Windows User account?
    Thanks!

    What happens if you rename the iPhone "Wife" when it shows up as "Hubby", then choose a different set of apps/playlists to sync with? iTunes is supposed to be able to manage multiple devices, each with their own selection of content. Perhaps you "restored" "Wife" with a backup from "Hubby" when you first set things up which is now causing confusion.
    To create a new library press and hold down the shift key as you click the icon to start iTunes and keep holding shift until asked to choose or create a library. You need to use the same technique to switch back.
    tt2

Maybe you are looking for

  • Photoshop elements wont download on mac

    i purchased photoshop elements 11 for my mac osx 10.8.2 and its not downloading. ive also tried downloading the trial version so that i can just punch in the product key after but it wont download all the way keeps saying theres an error. need help o

  • Want to bridge two wired ethernet connections

    I have a Core Duo based Mini that was just replaced with a new aluminum MacBook. I am going to re-purpose the mini as a media center device. I already have a TiVo HD unit hooked up to the same TV. The TiVo is hooked up through a wired ethernet connec

  • Individual Cell Width?

    I am trying to change the width of a individual cell within a table in Dreamweaver 8, however when I click and drag to change the width, it also grabs the cell above it, changing both cells, however I only want to have the width of one cell changed.

  • Photoshop Element 13 download fails : system busy

    Hi ! I don't succeed in downloading Photoshop Elements 13.0 MAC ESD LRF from LWS. I tried several times and I always got an error message "Echec - Système occupé" (in French, which means "Failure - System busy"). In the target folder I find a file "N

  • I can't get any sound out of iTunes when i play a song.

    Ever since i upgraded iTunes i can't get any sound out of it. The player shows the bar moving through the song but nothing is heard.