How to use paintComponent

I'm pretty new to graphics programing in java. I was wondering how you would implement paintComponent, so that my graphics will remain onscreen.
Here is my code.
import javax.swing.*;
import java.awt.*;
class main extends JFrame
     public JFrame mainFrame = new JFrame("Test");
     public Container mainPane = mainFrame.getContentPane();
     public GraphicsEnvironment ev = GraphicsEnvironment.getLocalGraphicsEnvironment();
     public Point DEFAULT_WINDOW_POSITION = new Point(ev.getCenterPoint());
     public Graphics g;
     public static void main(String[] args)
          main m = new main();
     public main()
          mainFrame.setSize(600,500);
          mainFrame.setResizable(false);
          mainFrame.setLocation((int)DEFAULT_WINDOW_POSITION.getX()-((int)mainFrame.getWidth()/2),(int)DEFAULT_WINDOW_POSITION.getY()-((int)mainFrame.getHeight()/2));
          mainPane.setBackground(Color.white);
          mainPane.setLayout(null);
          mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          mainFrame.setVisible(true);
          g = mainPane.getGraphics();
          drawSomething(g);
     public void drawSomething(Graphics g)
          g.fillRect(100,100,100,100);  //shows for 1/10 of a second.  why?
}

You misunderstood me.
class MyPanel extends JPanel
   public void paintComponent(Graphics g)
class MyFrame extends JFrame
   public MyFrame()
      setContentPane(new MyPanel());
}Get it?

Similar Messages

  • How to use Paintcomponent using parameters/variable

    Hi, I am new to Java.have looked in many topics of this forum, references and could not find the answer. thanks for helping.
    I am trying to test a simple procedure to draw a line from (0,0) to (x,x), where x is an integer entered by the user using a showInputDialog.
    I am using a JPanel and the paintComponent as suggested by some tutorial (so that, the frame can be moved, resized etc..and the line still remains there).
    I have tried for hours how to get the x variable into the g.drawline method. Can anyone help.
    Additionally, my frame has its top-left corner centered on the screen, resulting in the frame being shown in the bottom-right quadrant of the PC screen. How do I center it?
    thanks for the help
    package graphictest;
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Draw extends JFrame {
         public Draw(){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
            String inputString = JOptionPane.showInputDialogu(null,"enter input")l
            int input;
            input = Integer.parseInt(inputString);
            add(new NewPanel());
         public class NewPanel extends JPanel {
               protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawLine(0, 0,input, input);
        public static void main(String[] args) {  
            Draw frame = new Draw();
            frame.setTitle("Title");
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800,800);
            frame.setVisible(true);
    }

    You need to make the variable input a class variable, not a variable local to any one method:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class Draw extends JFrame
        private int input = 0; //*** you need input to be a class variable
        public Draw()
            String inputString = JOptionPane.showInputDialog(null, "enter input");
            //int input;  //*** and not a variable local to this method!
            input = Integer.parseInt(inputString);
            add(new NewPanel());
        public class NewPanel extends JPanel
            protected void paintComponent(Graphics g)
                super.paintComponent(g);
                g.drawLine(0, 0, input, input);
        public static void main(String[] args)
            Draw frame = new Draw();
            frame.setTitle("Title");
            //frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //frame.setSize(800, 800);
            frame.setPreferredSize(new Dimension(800, 800));
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

  • How to use the Rectangle class to draw an image and center it in a JPanel

    I sent an earlier post on how to center an image in a JPanel using the Rectangle class. I was asked to send an executable code which will show the malfunction. The code below is an executable code and a small part of a very big project. To simplifiy things, it is just a JFrame and a JPanel with an open dialog. Once executed the JFrame and the FileDialog will open. You can then navigate to a .gif or a .jpg picture and open it. What I want is for the picture to be centered in the middle of the JPanel and not the upper left corner. It is also important to stress that, I am usinig the Rectangle class to draw the Image. The region of interest is where the rectangle is created. In the constructor of the CenterRect class, I initialize the Rectangle class. Then I use paintComponent in the CenterRect class to draw the Image. The other classes are just support classes. The MyImage class is an extended image class which also has a draw() method. Any assistance in getting the Rectangle to show at the center of the JPanel without affecting the size and shape of the image will be greatly appreciated.
    I have divided the code into three parts. They are all supposed to be on one file in order to execute.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class CenterRect extends JPanel {
        public static Rectangle srcRect;
        Insets insets = null;
        Image image;
        MyImage imp;
        private double magnification;
        private int dstWidth, dstHeight;
        public CenterRect(MyImage imp){
            insets = getInsets();
            this.imp = imp;
            int width = imp.getWidth();
            int height = imp.getHeight();
            ImagePanel.init();
            srcRect = new Rectangle(0,0, width, height);
            srcRect.setLocation(0,0);
            setDrawingSize(width, height);
            magnification = 1.0;
        public void setDrawingSize(int width, int height) {
            dstWidth = width;
            dstHeight = height;
            setSize(dstWidth, dstHeight);
        public void paintComponent(Graphics g) {
            Image img = imp.getImage();
         try {
                if (img!=null)
                    g.drawImage(img,0,0, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
              srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height, null);
            catch(OutOfMemoryError e) {e.printStackTrace();}
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Opener().openImage();
    class Opener{
        private String dir;
        private String name;
        private static String defaultDirectory;
        JFrame parent;
        public Opener() {
            initComponents();
         public void initComponents(){
            parent = new JFrame();
            parent.setContentPane(ImagePanel.panel);
            parent.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            parent.setExtendedState(JFrame.MAXIMIZED_BOTH);
            parent.setVisible(true);
        public void openDialog(String title, String path){
            if (path==null || path.equals("")) {
                FileDialog fd = new FileDialog(parent, title);
                defaultDirectory = "dir.image";
                if (defaultDirectory!=null)
                    fd.setDirectory(defaultDirectory);
                fd.setVisible(true);
                name = fd.getFile();
                if (name!=null) {
                    dir = fd.getDirectory();
                    defaultDirectory = dir;
                fd.dispose();
                if (parent==null)
                    return;
            } else {
                int i = path.lastIndexOf('/');
                if (i==-1)
                    i = path.lastIndexOf('\\');
                if (i>0) {
                    dir = path.substring(0, i+1);
                    name = path.substring(i+1);
                } else {
                    dir = "";
                    name = path;
        public MyImage openImage(String directory, String name) {
            MyImage imp = openJpegOrGif(dir, name);
            return imp;
        public void openImage() {
            openDialog("Open...", "");
            String directory = dir;
            String name = this.name;
            if (name==null)
                return;
            MyImage imp = openImage(directory, name);
            if (imp!=null) imp.show();
        MyImage openJpegOrGif(String dir, String name) {
                MyImage imp = null;
                Image img = Toolkit.getDefaultToolkit().getImage(dir+name);
                if (img!=null) {
                    imp = new MyImage(name, img);
                    FileInfo fi = new FileInfo();
                    fi.fileFormat = fi.GIF_OR_JPG;
                    fi.fileName = name;
                    fi.directory = dir;
                    imp.setFileInfo(fi);
                return imp;
    }

    This is the second part. It is a continuation of the first part. They are all supposed to be on one file.
    class MyImage implements ImageObserver{
        private int imageUpdateY, imageUpdateW,width,height;
        private boolean imageLoaded;
        private static int currentID = -1;
        private int ID;
        private static Component comp;
        protected ImageProcessor ip;
        private String title;
        protected Image img;
        private static int xbase = -1;
        private static int ybase,xloc,yloc;
        private static int count = 0;
        private static final int XINC = 8;
        private static final int YINC = 12;
        private int originalScale = 1;
        private FileInfo fileInfo;
        ImagePanel win;
        /** Constructs an ImagePlus from an AWT Image. The first argument
         * will be used as the title of the window that displays the image. */
        public MyImage(String title, Image img) {
            this.title = title;
             ID = --currentID;
            if (img!=null)
                setImage(img);
        public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
             imageUpdateY = y;
             imageUpdateW = w;
             imageLoaded = (flags & (ALLBITS|FRAMEBITS|ABORT)) != 0;
         return !imageLoaded;
        public int getWidth() {
             return width;
        public int getHeight() {
             return height;
        /** Replaces the ImageProcessor, if any, with the one specified.
         * Set 'title' to null to leave the image title unchanged. */
        public void setProcessor(String title, ImageProcessor ip) {
            if (title!=null) this.title = title;
            this.ip = ip;
            img = ip.createImage();
            boolean newSize = width!=ip.getWidth() || height!=ip.getHeight();
         width = ip.getWidth();
         height = ip.getHeight();
         if (win!=null && newSize) {
                win = new ImagePanel(this);
        public void draw(){
            CenterRect ic = null;
            win = new ImagePanel(this);
            if (win!=null){
                win.addIC(this);
                win.getCanvas().repaint();
                ic = win .getCanvas();
                win.panel.add(ic);
                int width = win.imp.getWidth();
                int height = win.imp.getHeight();
                Point ijLoc = new Point(10,32);
                if (xbase==-1) {
                    xbase = 5;
                    ybase = ijLoc.y;
                    xloc = xbase;
                    yloc = ybase;
                if ((xloc+width)>ijLoc.x && yloc<(ybase+20))
                    yloc = ybase+20;
                    int x = xloc;
                    int y = yloc;
                    xloc += XINC;
                    yloc += YINC;
                    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                    count++;
                    if (count%6==0) {
                        xloc = xbase;
                        yloc = ybase;
                    int scale = 1;
                    while (xbase+XINC*4+width/scale>screen.width || ybase+YINC*4+height/scale>screen.height)
                        if (scale>1) {
                   originalScale = scale;
                   ic.setDrawingSize(width/scale, height/scale);
        /** Returns the current AWT image. */
        public Image getImage() {
            if (img==null && ip!=null)
                img = ip.createImage();
            return img;
        /** Replaces the AWT image, if any, with the one specified. */
        public void setImage(Image img) {
            waitForImage(img);
            this.img = img;
            JPanel panel = ImagePanel.panel;
            width = img.getWidth(panel);
            height = img.getHeight(panel);
            ip = null;
        /** Opens a window to display this image and clears the status bar. */
        public void show() {
            show("");
        /** Opens a window to display this image and displays
         * 'statusMessage' in the status bar. */
        public void show(String statusMessage) {
            if (img==null && ip!=null){
                img = ip.createImage();
            if ((img!=null) && (width>=0) && (height>=0)) {
                win = new ImagePanel(this);
                draw();
        private void waitForImage(Image img) {
        if (comp==null) {
            comp = ImagePanel.panel;
            if (comp==null)
                comp = new JPanel();
        imageLoaded = false;
        if (!comp.prepareImage(img, this)) {
            double progress;
            while (!imageLoaded) {
                if (imageUpdateW>1) {
                    progress = (double)imageUpdateY/imageUpdateW;
                    if (!(progress<1.0)) {
                        progress = 1.0 - (progress-1.0);
                        if (progress<0.0) progress = 0.9;
    public void setFileInfo(FileInfo fi) {
        fi.pixels = null;
        fileInfo = fi;
    }

  • Need a Big Help please on how to use getAppletContext() method

    I have three classes, first one extends JApplet, second class I use two create my popup menus, third class I use for my main actions to be done. I need when a popup menu is clicked to load a page, but I am getting this error.
    java.lang.NullPointerException
    at java.applet.Applet.getAppletContext(Applet.java:171)
    at Popup_Menus$1.actionPerformed(Popup_Menus.java:90)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
    at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Ev
    My Code is messy, but here it is: -
    Class One
    //package final_project;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    public class Main_Interface extends JApplet implements Runnable {
    GUICanvas MainCanvas;
    int counter = 0;
    protected int delay = 10000;
    private Thread timeThread= null;
         public void init() {
         Container contentPane = getContentPane();
    MainCanvas = new GUICanvas();
    contentPane.setBounds(0,0,850,650);
         contentPane.add(MainCanvas);
    public void start() {
    timeThread = new Thread(this);
    timeThread.start();
    public void run() {
    Thread myThread = Thread.currentThread();
    while (timeThread == myThread) {
    try {
    Thread.currentThread().sleep(delay);
    } catch (InterruptedException e){}
    counter ++;
    MainCanvas.TheKing();
    Class Two
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    import java.applet.*;
    public class Popup_Menus extends Applet implements MouseListener {
    JPopupMenu ar[] = new JPopupMenu[16];
    JMenuItem it[] = new JMenuItem[84];
    public Popup_Menus() {
    for (int i=0;i<16;i++)
    ar[i] = new JPopupMenu();
    for (int i=0;i<84;i++)
    it[i] = new JMenuItem();
    it.setBackground(Color.orange);
    it[i].setForeground(Color.cyan);
    it[16]= new JMenuItem("Shop Details");
    it[17]= new JMenuItem("NoOfStaff");
    it[18]= new JMenuItem("ShopAssest");
    it[0] = new JMenuItem("Oracle");
    ar[0].add(it[0]);
    it[1] = new JMenuItem("Macrosoft");
    ar[1].add(it[1]);
    it[2] = new JMenuItem("SunMicro");
    ar[2].add(it[2]);
    it[3] = new JMenuItem("PeopleSoft");
    ar[3].add(it[3]);
    it[4] = new JMenuItem("HP");
    ar[4].add(it[4]);
    it[5] = new JMenuItem("Dell");
    ar[5].add(it[5]);
    it[6] = new JMenuItem("Compact");
    ar[6].add(it[6]);
    it[7] = new JMenuItem("Apple");
    ar[7].add(it[7]);
    it[8] = new JMenuItem("Sony");
    ar[8].add(it[8]);
    it[9] = new JMenuItem("Philipes");
    ar[9].add(it[9]);
    it[10] = new JMenuItem("Bush");
    ar[10].add(it[0]);
    it[11] = new JMenuItem("Granada");
    ar[11].add(it[11]);
    it[12] = new JMenuItem("PC");
    ar[12].add(it[12]);
    it[13] = new JMenuItem("Macintosh");
    ar[13].add(it[13]);
    it[14] = new JMenuItem("Laptop");
    ar[14].add(it[14]);
    it[15] = new JMenuItem("Solaris");
    ar[15].add(it[15]);
    it[0].addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    ar[0].add(it[16]);
    ar[0].add(it[17]);
    ar[0].add(it[18]);
    System.out.println("Working");
    // ma = new Main_Interface();
    try
    System.out.println("menuitem");
    String s="ali";
    URL url = new URL("http://www.google.com");
    getAppletContext().showDocument(url,s);
    catch(MalformedURLException malformedurlexception)
    System.err.println(malformedurlexception);
    public void mouseClicked(java.awt.event.MouseEvent e) {
    //ar[0].show(this,30,30);
    public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {
    public void mouseExited(java.awt.event.MouseEvent mouseEvent) {
    public void mousePressed(java.awt.event.MouseEvent mouseEvent) {
    public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {
    Class Three
    //package final_project;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    public class GUICanvas extends JPanel implements MouseMotionListener,ActionListener,MouseListener
    private Color color;
    Popup_Menus popup = new Popup_Menus();
    private Font font;
    double a1, Q = 0,Z = 0,P = 1, S1;
    String Percentages;
    double Aa=0,Ba=0,Ca=0,Da=0;
    double Aa1=0,Ba1=0,Ca1=0,Da1=0;
    double Aa2=0,Ba2=0,Ca2=0,Da2=0;
    double Aa3=0,Ba3=0,Ca3=0,Da3=0;
    double Aa4=0,Ba4=0,Ca4=0,Da4=0;
    double Sum = 0,Sum1 = 0, Sum2 = 0, Sum3 = 0, Sum4 = 0;
    double A=0, B=0, C=0, D=0;
    double A1=0, B1=0, C1=0, D1=0,A2=0, B2=0, C2=0, D2=0;
    double k1=0,k2=0,l1=0,l2=0,r1=0,r2=0,u1=0,u2=0;
    int xpos,ypos,popcounter=0;
    double DC1[] = new double[4];
    double DC2[] = new double[4];
    double DC3[] = new double[4];
    double DC4[] = new double[4];
    boolean rect1Active[] = new boolean[4];
    boolean rect1Active2[] = new boolean[4];
    boolean rect1Active3[] = new boolean[4];
    boolean rect1Active4[] = new boolean[4];
    double DF1[] = new double[4];
    double DF2[] = new double[4];
    double DF3[] = new double[4];
    double DF4[] = new double[4];
    double Ap[] = new double[4];
    double Bp[] = new double[4];
    double Cp[] = new double[4];
    double Dp[] = new double[4];
    int rect1width[] = new int[4];
    int rect1height[] = new int[4];
    int rect1xco[] = new int[4];
    int rect1yco[] = new int[4];
    int rect1width2[] = new int[4];
    int rect1height2[] = new int[4];
    int rect1xco2[] = new int[4];
    int rect1yco2[] = new int[4];
    int rect1width3[] = new int[4];
    int rect1height3[] = new int[4];
    int rect1xco3[] = new int[4];
    int rect1yco3[] = new int[4];
    int rect1width4[] = new int[4];
    int rect1height4[] = new int[4];
    int rect1xco4[] = new int[4];
    int rect1yco4[] = new int[4];
    double rect1width5[] = new double[4];
    double rect1height5[] = new double[4];
    double rect1xco5[] = new double[4];
    double rect1yco5[] = new double[4];
    public GUICanvas() {
    setBackground( Color.black );
    TheKing();
    addMouseListener(this);
    addMouseMotionListener(this);
    public void TheKing()
    double X=740, Y=470, Ap=0,Bp=0,Cp=0,Dp=0;
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    }catch (Exception e){
    e.printStackTrace();
    line[0] = "200";
    line[1] = "200";
    line[2] = "200";
    line[3] = "200";
    Aa = s2d(line[0]);
    Ba = s2d(line[1]);
    Ca = s2d(line[2]);
    Da = s2d(line[3]);
    rect1xco5[0] = 20;
    rect1yco5[0] = 20;
    Sum=Aa+Ba+Ca+Da;
    Ap = (Aa/Sum)*100;
    Bp = (Ba/Sum)*100;
    Cp = (Ca/Sum)*100;
    Dp = (Da/Sum)*100;
    A= (Ap/100)*(X*Y);
    B= (Bp/100)*(X*Y);
    C= (Cp/100)*(X*Y);
    D= (Dp/100)*(X*Y);
    Q = ((A*C)+(X*Y*D)+(X*C*Y)+(B*X*Y)-(Y*A*X)-((X*X)*(Y*Y))-(B*D))/((X*(Y*Y))-(Y*D)-(C*Y));
    Z = (((X*X)*Y*A)-(X*C*A)-(B*X*A))/((X*(Y*Y))-(Y*D)-(C*Y));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X-A1;
    B2=B/B1;
    D2=Y-A2;
    D1=D/D2;
    C1=X-D1;
    C2=C/C1;
    S1=B2+C2;
    rect1width5[0] = d2i(A1);
    rect1height5[0] = d2i(A2);
    rect1width5[1] = d2i(B1);
    rect1height5[1] = d2i(B2);
    rect1width5[2] = d2i(D1);
    rect1height5[2] = d2i(D2);
    rect1width5[3] = d2i(C1);
    rect1height5[3] = d2i(C2);
    rect1xco5[1] = rect1xco5[0] + rect1width5[0];
    rect1yco5[1] = rect1xco5[0];
    rect1xco5[2] = rect1xco5[0];
    rect1yco5[2] = rect1yco5[0] + rect1height5[0];
    rect1xco5[3] = rect1xco5[0] + rect1width5[2];
    rect1yco5[3] = rect1yco5[0] + rect1height5[1];
    k1=rect1xco5[0]+rect1width5[0];
    k2=rect1yco5[0]+rect1height5[0];
    l1=rect1width5[1]-20;
    l2=rect1yco5[1]+rect1height5[1];
    r1=rect1xco5[0]+rect1width5[2];
    r2=rect1height5[2]-20;
    u1=rect1width5[3]-20;
    u2=rect1height5[3]-20;
    RegionOne(k1, k2);
    RegionTwo(l1,l2);
    RegionThree(r1, r2);
    RegionFour(u1, u2);
    public void RegionOne(double X1, double Y1)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=ONE");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    }catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC1[0] = Aa1 ;
    DC1[1] = Ba1 ;
    DC1[2] = Ca1;
    DC1[3] = Da1;
    Aa1 = s2d(line[0]);
    Ba1 = s2d(line[1]);
    Ca1 = s2d(line[2]);
    Da1 = s2d(line[3]);
    DF1[0] = Aa1 ;
    DF1[1] = Ba1 ;
    DF1[2] = Ca1;
    DF1[3] = Da1;
    rect1xco[0] = 20;
    rect1yco[0] = 20;
    Sum1=Aa1+Ba1+Ca1+Da1;
    Ap[0] = (Aa1/Sum1)*100;
    Bp[0] = (Ba1/Sum1)*100;
    Cp[0] = (Ca1/Sum1)*100;
    Dp[0] = (Da1/Sum1)*100;
    A= (Ap[0]/100)*(X1*Y1);
    B= (Bp[0]/100)*(X1*Y1);
    C= (Cp[0]/100)*(X1*Y1);
    D= (Dp[0]/100)*(X1*Y1);
    Q = ((A*C)+(X1*Y1*D)+(X1*C*Y1)+(B*X1*Y1)-(Y1*A*X1)-((X1*X1)*(Y1*Y1))-(B*D))/((X1*(Y1*Y1))-(Y1*D)-(C*Y1));
    Z = (((X1*X1)*Y1*A)-(X1*C*A)-(B*X1*A))/((X1*(Y1*Y1))-(Y1*D)-(C*Y1));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X1-A1;
    B2=B/B1;
    D2=Y1-A2;
    D1=D/D2;
    C1=X1-D1;
    C2=C/C1;
    S1=B2+C2;
    rect1width[0] = d2i(A1);
    rect1height[0] = d2i(A2);
    rect1width[1] = d2i(B1);
    rect1height[1] = d2i(B2);
    rect1width[2] = d2i(D1);
    rect1height[2] = d2i(D2);
    rect1width[3] = d2i(C1);
    rect1height[3] = d2i(C2);
    rect1xco[1] = rect1xco[0] + rect1width[0];
    rect1yco[1] = rect1xco[0];
    rect1xco[2] = rect1xco[0];
    rect1yco[2] = rect1yco[0] + rect1height[0];
    rect1xco[3] = rect1xco[0] + rect1width[2];
    rect1yco[3] = rect1yco[0] + rect1height[1];
    public void RegionTwo(double X2, double Y2)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=TWO");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC2[0] = Aa2;
    DC2[1] = Ba2;
    DC2[2] = Ca2;
    DC2[3] = Da2;
    Aa2 = s2d(line[0]);
    Ba2 = s2d(line[1]);
    Ca2 = s2d(line[2]);
    Da2 = s2d(line[3]);
    DF2[0] = Aa2 ;
    DF2[1] = Ba2 ;
    DF2[2] = Ca2;
    DF2[3] = Da2;
    rect1xco2[0] = rect1xco[1]+rect1width[1];
    rect1yco2[0] = 20;
    Sum2=Aa2+Ba2+Ca2+Da2;
    Ap[1] = (Aa2/Sum2)*100;
    Bp[1] = (Ba2/Sum2)*100;
    Cp[1] = (Ca2/Sum2)*100;
    Dp[1] = (Da2/Sum2)*100;
    A= (Ap[1]/100)*(X2*Y2);
    B= (Bp[1]/100)*(X2*Y2);
    C= (Cp[1]/100)*(X2*Y2);
    D= (Dp[1]/100)*(X2*Y2);
    Q = ((A*C)+(X2*Y2*D)+(X2*C*Y2)+(B*X2*Y2)-(Y2*A*X2)-((X2*X2)*(Y2*Y2))-(B*D))/((X2*(Y2*Y2))-(Y2*D)-(C*Y2));
    Z = (((X2*X2)*Y2*A)-(X2*C*A)-(B*X2*A))/((X2*(Y2*Y2))-(Y2*D)-(C*Y2));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X2-A1;
    B2=B/B1;
    D2=Y2-A2;
    D1=D/D2;
    C1=X2-D1;
    C2=C/C1;
    rect1width2[0] = d2i(A1);
    rect1height2[0] = d2i(A2);
    rect1width2[1] = d2i(B1);
    rect1height2[1] = d2i(B2);
    rect1width2[2] = d2i(D1);
    rect1height2[2] = d2i(D2);
    rect1width2[3] = d2i(C1);
    rect1height2[3] = d2i(C2);
    rect1xco2[1] = rect1xco2[0] + rect1width2[0];
    rect1yco2[1] = rect1yco2[0];
    rect1xco2[2] = rect1xco2[0];
    rect1yco2[2] = rect1yco2[0] + rect1height2[0];
    rect1xco2[3] = rect1xco2[0] + rect1width2[2];
    rect1yco2[3] = rect1yco2[0] + rect1height2[1];
    public void RegionThree(double X3, double Y3)
    String line[] = new String[4];
    /* try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=THREE");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC3[0] = Aa3 ;
    DC3[1] = Ba3 ;
    DC3[2] = Ca3;
    DC3[3] = Da3;
    Aa3 = s2d(line[0]);
    Ba3 = s2d(line[1]);
    Ca3 = s2d(line[2]);
    Da3 = s2d(line[3]);
    DF3[0] = Aa3 ;
    DF3[1] = Ba3;
    DF3[2] = Ca3;
    DF3[3] = Da3;
    rect1xco3[0] = 20;
    rect1yco3[0] = rect1yco[2]+rect1height[2];
    Sum3=Aa3+Ba3+Ca3+Da3;
    Ap[2] = (Aa3/Sum3)*100;
    Bp[2] = (Ba3/Sum3)*100;
    Cp[2] = (Ca3/Sum3)*100;
    Dp[2] = (Da3/Sum3)*100;
    A= (Ap[2]/100)*(X3*Y3);
    B= (Bp[2]/100)*(X3*Y3);
    C= (Cp[2]/100)*(X3*Y3);
    D= (Dp[2]/100)*(X3*Y3);
    Q = ((A*C)+(X3*Y3*D)+(X3*C*Y3)+(B*X3*Y3)-(Y3*A*X3)-((X3*X3)*(Y3*Y3))-(B*D))/((X3*(Y3*Y3))-(Y3*D)-(C*Y3));
    Z = (((X3*X3)*Y3*A)-(X3*C*A)-(B*X3*A))/((X3*(Y3*Y3))-(Y3*D)-(C*Y3));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X3-A1;
    B2=B/B1;
    D2=Y3-A2;
    D1=D/D2;
    C1=X3-D1;
    C2=C/C1;
    rect1width3[0] = d2i(A1);
    rect1height3[0] = d2i(A2);
    rect1width3[1] = d2i(B1);
    rect1height3[1] = d2i(B2);
    rect1width3[2] = d2i(D1);
    rect1height3[2] = d2i(D2);
    rect1width3[3] = d2i(C1);
    rect1height3[3] = d2i(C2);
    rect1xco3[1] = rect1xco3[0] + rect1width3[0];
    rect1yco3[1] = rect1yco[3] + rect1height[3];
    rect1xco3[2] = rect1xco3[0];
    rect1yco3[2] = rect1yco3[0] + rect1height3[0];
    rect1xco3[3] = rect1xco3[0] + rect1width3[2];
    rect1yco3[3] = rect1yco3[0] + rect1height3[1];
    public void RegionFour(double X4, double Y4)
    String line[] = new String[4];
    /*try {
    URL url = new URL(
         "http://localhost:111/test/servlet/TestServlet1?name=FOUR");
    BufferedReader in = new BufferedReader(
         new InputStreamReader(url.openStream()));
    for (int i = 0; i<4; i++)
    line[i] = in.readLine();
    in.close();
    catch (Exception e){
    e.printStackTrace();
    line[0] = "1200";
    line[1] = "2100";
    line[2] = "1200";
    line[3] = "2100";
    DC4[0] = Aa4 ;
    DC4[1] = Ba4 ;
    DC4[2] = Ca4;
    DC4[3] = Da4;
    Aa4 = s2d(line[0]);
    Ba4 = s2d(line[1]);
    Ca4 = s2d(line[2]);
    Da4 = s2d(line[3]);
    DF4[0] = Aa4 ;
    DF4[1] = Ba4 ;
    DF4[2] = Ca4;
    DF4[3] = Da4;
    rect1xco4[0] = rect1xco3[1]+rect1width3[1];
    rect1yco4[0] = rect1yco2[2]+rect1height2[2];
    Sum4=Aa4+Ba4+Ca4+Da4;
    Ap[3] = (Aa4/Sum4)*100;
    Bp[3] = (Ba4/Sum4)*100;
    Cp[3] = (Ca4/Sum4)*100;
    Dp[3] = (Da4/Sum4)*100;
    A= (Ap[3]/100)*(X4*Y4);
    B= (Bp[3]/100)*(X4*Y4);
    C= (Cp[3]/100)*(X4*Y4);
    D= (Dp[3]/100)*(X4*Y4);
    Q = ((A*C)+(X4*Y4*D)+(X4*C*Y4)+(B*X4*Y4)-(Y4*A*X4)-((X4*X4)*(Y4*Y4))-(B*D))/((X4*(Y4*Y4))-(Y4*D)-(C*Y4));
    Z = (((X4*X4)*Y4*A)-(X4*C*A)-(B*X4*A))/((X4*(Y4*Y4))-(Y4*D)-(C*Y4));
    A1 =((-Q) + (Math.sqrt((Q*Q)-(4*P*Z))))/(2*P);
    A2=A/A1;
    B1=X4-A1;
    B2=B/B1;
    D2=Y4-A2;
    D1=D/D2;
    C1=X4-D1;
    C2=C/C1;
    rect1width4[0] = d2i(A1);
    rect1height4[0] = d2i(A2);
    rect1width4[1] = d2i(B1);
    rect1height4[1] = d2i(B2);
    rect1width4[2] = d2i(D1);
    rect1height4[2] = d2i(D2);
    rect1width4[3] = d2i(C1);
    rect1height4[3] = d2i(C2);
    rect1xco4[1] = rect1xco4[0] + rect1width4[0];
    rect1yco4[1] = rect1yco2[2]+rect1height2[2];
    rect1xco4[2] = rect1xco4[0];
    rect1yco4[2] = rect1yco4[0] + rect1height4[0];
    rect1xco4[3] = rect1xco4[0] + rect1width4[2];
    rect1yco4[3] = rect1yco4[0] + rect1height4[1];
    static int d2i(double d) {return (int) Math.round(d);}
    static double i2d(int i) {return (double) i;}
    static double s2d(String s)
    double i=0;
    try{  return i = Double.parseDouble(s);}
    catch(NumberFormatException e)
    {  e.printStackTrace();}
    return i;
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int k11=d2i(k1);
    int k21=d2i(k2);
    int l11=d2i(l1);
    int l21=d2i(l2);
    int r11=d2i(r1);
    int r21=d2i(r2);
    int u11=d2i(u1);
    int u21=d2i(u2);
    g.setColor(Color.magenta);
    g.drawRect(rect1xco[0]-2,rect1yco[0]-2,k11+2,k21+2);
    g.drawRect(rect1xco[0]-1,rect1yco[0]-1,k11+2,k21+1);
    g.drawRect(rect1xco2[0]+1,rect1yco2[0]-1,l11+1,l21+1);
    g.drawRect(rect1xco2[0]+1,rect1yco2[0]-2,l11+2,l21+2);
    g.drawRect(rect1xco3[0]-1,rect1yco3[0]+1,r11+2,r21+1);
    g.drawRect(rect1xco3[0]-2,rect1yco3[0]+1,r11+2,r21+2);
    g.drawRect(rect1xco4[0]+1,rect1yco4[0]+1,u11+2,u21+1);
    g.drawRect(rect1xco4[0]+1,rect1yco4[0]+1,u11+1,u21+2);
    g.setColor(Color.cyan);
    g.drawRect(16,16,749,479);
    g.drawRect(17,17,747,477);
    if (rect1Active[0])
    // First Rectangle's coloring of the Region One
    if(DC1[0] == DF1[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else if(DC1[0] > DF1[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else if(DC1[0] < DF1[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco[0]+2,rect1yco[0]+2,rect1width[0]-4,rect1height[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[0],rect1yco[0],rect1width[0]-1,rect1height[0]-1);
    g.drawRect(rect1xco[0]+1,rect1yco[0]+1,rect1width[0]-3,rect1height[0]-3);
    else
    if(DC1[0] == DF1[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    else if(DC1[0] > DF1[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    else if(DC1[0] < DF1[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco[0],rect1yco[0],rect1width[0],rect1height[0]);
    if (rect1Active[1])
    // Second Rectangle's coloring of the Region One
    if(DC1[1] == DF1[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else if(DC1[1] > DF1[1])
    g.setColor(Color.red);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else if(DC1[1] < DF1[1])
    g.setColor(Color.green);
    g.fillRect(rect1xco[1]+2,rect1yco[1]+2,rect1width[1]-4,rect1height[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[1],rect1yco[1],rect1width[1]-1,rect1height[1]-1);
    g.drawRect(rect1xco[1]+1,rect1yco[1]+1,rect1width[1]-3,rect1height[1]-3);
    else
    if(DC1[1] == DF1[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    else if(DC1[1] > DF1[1])
    g.setColor(Color.red);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    else if(DC1[1] < DF1[1])
    g.setColor(Color.green);
    g.fillRect(rect1xco[1],rect1yco[1],rect1width[1],rect1height[1]);
    if (rect1Active [2])
    // Third Rectangle's coloring of the Region One
    if(DC1[2] == DF1[2])
    g.setColor(Color.black);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else if(DC1[2] > DF1[2])
    g.setColor(Color.red);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else if(DC1[2] < DF1[2])
    g.setColor(Color.green);
    g.fillRect(rect1xco[2]+2,rect1yco[2]+2,rect1width[2]-4,rect1height[2]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[2],rect1yco[2],rect1width[2]-1,rect1height[2]-1);
    g.drawRect(rect1xco[2]+1,rect1yco[2]+1,rect1width[2]-3,rect1height[2]-3);
    else
    if(DC1[2] == DF1[2])
    g.setColor(Color.black);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    else if(DC1[2] > DF1[2])
    g.setColor(Color.red);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    else if(DC1[2] < DF1[2])
    g.setColor(Color.green);
    g.fillRect(rect1xco[2],rect1yco[2],rect1width[2],rect1height[2]);
    if (rect1Active [3])
    //Fourth Rectangle's coloring of the Region One
    if(DC1[3] == DF1[3])
    g.setColor(Color.black);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else if(DC1[3] > DF1[3])
    g.setColor(Color.red);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else if(DC1[3] < DF1[3])
    g.setColor(Color.green);
    g.fillRect(rect1xco[3]+2,rect1yco[3]+2,rect1width[3]-4,rect1height[3]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco[3],rect1yco[3],rect1width[3]-1,rect1height[3]-1);
    g.drawRect(rect1xco[3]+1,rect1yco[3]+1,rect1width[3]-3,rect1height[3]-3);
    else
    if(DC1[3] == DF1[3])
    g.setColor(Color.black);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    else if(DC1[3] > DF1[3])
    g.setColor(Color.red);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    else if(DC1[3] < DF1[3])
    g.setColor(Color.green);
    g.fillRect(rect1xco[3],rect1yco[3],rect1width[3],rect1height[3]);
    if (rect1Active2[0])
    // First Rectangle's coloring of the Region Two
    if(DC2[0] == DF2[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else if(DC2[0] > DF2[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else if(DC2[0] < DF2[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco2[0]+4,rect1yco2[0]+2,rect1width2[0]-4,rect1height2[0]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0]-1,rect1height2[0]-1);
    g.drawRect(rect1xco2[0]+3,rect1yco2[0]+1,rect1width2[0]-3,rect1height2[0]-3);
    else
    if(DC2[0] == DF2[0])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    else if(DC2[0] > DF2[0])
    g.setColor(Color.red);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    else if(DC2[0] < DF2[0])
    g.setColor(Color.green);
    g.fillRect(rect1xco2[0]+2,rect1yco2[0],rect1width2[0],rect1height2[0]);
    if (rect1Active2[1])
    // Second Rectangle's coloring of the Region Two
    if(DC2[1] == DF2[1])
    g.setColor(Color.black);
    g.fillRect(rect1xco2[1]+4,rect1yco2[1]+2,rect1width2[1]-4,rect1height2[1]-4);
    g.setColor(Color.yellow);
    g.drawRect(rect1xco2[1]+2,rect1yco2[1],rect1width2[1]-1,rect1height2[1]-1);
    g.drawRect(rect1xco2[1]+3,rect1yco2[1]+1,rect1width2[1]-3,rect1height2[1]-3);

    Could you show me how to use it as an applet. If you
    can modify my code and make it working it would be
    very helpful.
    Best regards
    AliPerhaps you could start [url http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html]here[url                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Painting using paintComponent();

    hi guys, here i'm trying to paint over the JFrame which is using null layout.
    i have used paintComponent(). . . nothing is being displayed. i feel like i'm not adding the panel object to the JFrame properly.
    any idea why its not showing the message i'm trying to draw?????????????????????????
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class LoginScreen extends JFrame
         JLabel userId;
         JTextField userIdT;
         JButton userIdHelp;
         *WelcomeLogin welcome;*
         public LoginScreen()
              super("User Login Screen");
              Container surface = getContentPane();
              setSize(1024,750);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setLocationRelativeTo(null);
              surface.setLayout(null);
              *welcome = new WelcomeLogin();*
    *          surface.add(welcome);*
              userId = new JLabel("User ID       :",JLabel.LEFT);
              userId.setBounds(20,50,80,20);     surface.add(userId);
              userIdT = new JTextField(40);
              userIdT.setBounds(120,50,150,20);  surface.add(userIdT);
              userIdHelp = new JButton("?");    
              userIdHelp.setBounds(290,50,50,20);surface.add(userIdHelp);
              public static void main(String[] args)
              LoginScreen login = new LoginScreen();
              login.setVisible(true);
    class WelcomeLogin extends JPanel
         public void paintComponent(Graphics g)
              super.paintComponents(g);
              g.drawString("hey hi, how are you doing!",60,100);
    }

    Null layout has it's place, and if you've never used it and don't know how it works you really ought not to be giving out advice to others.Okay, you got me there. But..
    You don't always want a LayoutManager.Could you tell me why to use it when there is GroupLayout? And a bunch of other once as well. Cant the GroupLayout do the same thing, but better?
    EDIT: For some reason I find my self to want to know about the null layout, and hence Im reading this (also on the layout manager tutorial :S). Those reasons are as good as any for me to shut my trap. I shall try and be more educated on the matters I reply onto next time.
    Edited by: prigas on Apr 22, 2009 12:43 PM

  • How to use one email adress for multiple recipients

    Hello,
    I'd like to know how to use one email adress for multiple recipients. 
    this would be very useful or projects. for example;
    if i send one mail to [email protected], all people in this project get an email.
    I will add the people in this project myself. 
    I know it is possible, but I don't know how to do it ;-)
    please help me! 

    Hope this help.
    _http://technet.microsoft.com/en-us/library/cc164331(v=exchg.65) .aspx

  • Can't figure out how to use home sharing

    Since the latest couple iTunes updates, my family and I can not figure out how to use home sharing. Everyone in our household has their own iTunes, and for a long time we would just share our music through home sharing. But with the updates, so much has changed that we can no longer figure out how to use it.
    I have a lot of purchased albums on another laptop in the house, that im trying to move it all over to my own iTunes, and I have spent a long time searching the internet, and everything. And I just can't figure out how to do it. So.... how does it work now? I would really like to get these albums from my moms iTunes, onto mine. I would hate to have to buy them all over again.
    If anyone is able to help me out here, that would be great! Thanks!

    The problem im having is that after I am in another library through home sharing, I can't figure out how to select an album and import it to my library. They used to have it set up so that you just highlight all of the songs you want, and then all you had to do was click import. Now I don't even see an import button, or anything else like it. So im lost... I don't know if it's something im doing wrong, or if our home sharing system just isn't working properly.
    Thanks for the help.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • How to use airport time capsule with multiple computers?

    I'm sure there are some thread about this but i couldn't find it... so sorry for that but hear me out! =)
    I bought the AirPort Time Capsule to back up my MBP
    And so i did.
    then i thought "let give this one a fresh start" so i erased all of it with the disk utility and re-installed the MBP from the recovery disk.
    I dont want all of the stuff i backed up just a few files and some pictures so i brought that back.. so far so good.
    Now i want to do a new back up of my MBP so i open time machine settings, pick the drive on the time capsule and then "Choose" i wait for the beck up to begin, and then it fails.  It says (sorry for my bad english, im swedish haha) "the mount /Volume/Data-1/StiflersMBP.sparsebundle is already in use for back up.
    this is what i want:
    i want the "StiflersMBP.sparsebundle" to just be so i can get some stuf when i need them. it's never to be erased.
    i want to make a new back up of my MBP as if it's a second computer...
    so guys and girls, what is the easiest and best solution?
    Best regards!

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How to use multiple ipods on one account

    I have an Ipod classic and just bought my sons two nano's how do I use these on the same account without changing my account info?

    Take a look here:
    How to use multiple iPods with one computer
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Discussions page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums, in the User Tips Library and in the Apple Knowledge Base before you post a question.
    Regards.

  • How to use a Table View in AppleScriptObjC

    How can I use a table view and add data to it? And how can I display a button cell and image cell in the table? Thanks.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

  • How to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,

    how to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,
    i want the output should be seprated by '|' delimited when i download the file.

    Hi,
    We will pass the seperator to the WRITE_FIELD_SEPARATOR parameter as
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = v_file
    write_field_separator = '|'
    TABLES
    data_tab = itab[] . "Our internal talbe filled with data
    Re: Why Function GUI_DOWNLOAD can create XML file but not a flat file?
    Award points if useful
    Thanks,
    Ravee...

  • ** How to use TO_DATE function in Stored Proc. for JDBC in ABAP-XSL mapping

    Hi friends,
    I use ABAP-XSL mapping to insert records in Oracle table. My Sender is File and receiver is JDBC. We use Oracle 10g database. All fields in table are VARCHAR2 except one field; this is having type 'DATE'.
    I use Stored procedure to update the records in table. I have converted my string into date using the Oracle TO_DATE function. But, when I use this format, it throws an error in the Receiver CC. (But, the message is processed successfully in SXMB_MONI).
    The input format I formed like below:
    <X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">
    Value in Payload is like below.
    <X_EMP_START_DT hasQuot="No" isInput="1" type="DATE">TO_DATE('18-11-1991','DD-MM-YYYY')</X_EMP_START_DT>
    Error in CC comes as below:
    Error processing request in sax parser: Error when executing statement for table/stored proc. 'SP_EMP_DETAILS' (structure 'STATEMENT'): java.lang.NumberFormatException: For input string: "TO_DATE('18"
    Friends, I have tried, but unable to find the correct solution to insert.
    Kindly help me to solve this issue.
    Kind Regards,
    Jegathees P.
    (But, the same is working fine if we use direct method in ABAP-XSL ie. not thru Stored Procedure)

    Hi Sinha,
    Thanks for your reply.
    I used the syntax
    <xsl:call-template name="date:format-date">
       <xsl:with-param name="date-time" select="string" />
       <xsl:with-param name="pattern" select="string" />
    </xsl:call-template>
    in my Abap XSL.  But, its not working correctly. The problem is 'href' function to import "date.xsl" in my XSLT is not able to do that. The system throws an error. Moreover, it is not able to write the command 'extension-element-prefixes' in my <xsl:stylesheet namespace>
    May be I am not able to understand how to use this.
    Anyway, I solved this problem by handling date conversion inside Oracle Stored Procedure. Now, its working fine.
    Thank you.

  • Sender Mail Adapter - S/MIME - How to use it?

    Hi guys,
    I am trying to figure out how to use the S/MIME security parameter of the Sender Mail Adapter in PI 7.1.
    Could anyone point me to some useful documentation/examples/blogs ?
    Or perhaps explain what steps are involved when configuring this parameter?
    We are pulling emails from an Microsoft Exchange server.
    Many thanks,
    Aldo

    First of all one sender mail adapter has to be tight with a specific sender email address.
    The email has to be decrypted as whole, you cannot decrypt parts of it.
    Then you store certificates to secure store in J2EE server and point to it in send agreement, this should be equal to HTTPS setup
    Check security guide:
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/f7/c2953fc405330ee10000000a114084/frameset.htm

  • How to use Logical database in function module?

    I will create a function module in HR.
    but how to use Logical database  in function module ?  Logical database PNP always show screen.in function (RFC) code , it is a matter.

    You cannot attach the LDB to the main program of the function group.
    - So you may [SUBMIT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=submit&adv=false&sortby=cm_rnd_rankvalue] a report which use the LDB and get back the data (export/import), by default in the syntax of SUBMIT the selection-screen will not be displayed
    - Use [LDB_PROCESS|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=ldb_process&cat=sdn_all], fill a structured table for selection, and get data back in another table
    - Use [HR function modules to read Infotypes|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=hrfunctionmodulestoread+Infotypes&adv=false&sortby=cm_rnd_rankvalue].
    Regards

Maybe you are looking for

  • Onload and Tabbing focus problem

    I was asked by some of my users to set focus to the username field on the login page when it loads. I began by adding to the body tag and cfform tags OnLoad function. This allowed the page to load and set up the user to just start typing without clic

  • JSF1091: No mime type could be found for file image_name.png

    Hi Experts, JDEV 11.1.2 why this message shown in the log......? also how can i add a mime-type mapping ? <ExternalContextImpl> <getMimeType> JSF1091: No mime type could be found for file image_name.png. To resolve this, add a mime-type mapping to th

  • ABAP Development in SRM....?

    Experts can you pl tell... what is ABAP related development scope in SRM (Supplier Relationship Management)???

  • Can I print a contact sheet from Bridge?

    Does anyone know how I print a contact sheeet in Bridge?

  • Programs not staying in assigned spaces

    I've had an issue with Spaces ever since it came out.  Programs won't stay in their assigned Spaces.  It happens with MS Office (both 2004 and 2011), Adium (won't always show in all spaces when assigned to all spaces), Safari, Firefox, Chrome, iCal,