Results 1 to 2 of 2
  1. #1
    bigo005 is offline Member
    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Lightbulb Nothing except Frame and label shows up.

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    public class TestFrame extends Frame implements ActionListener
    {
    static int i;
    Frame fr;
    Button b1,b2;
    Image img[]=new Image[3];
    Label l;
    public TestFrame(){}
    public TestFrame(String str)
    {
    fr=new Frame(str);
    setBackground(Color.cyan);
    //Frame fr=new Frame(str);
    b1=new Button("PREVIOUS");
    b2=new Button("NEXT");
    l=new Label("To rotate through images press buttons given.");
    //fr.setName("Test Frame");
    /*b1.setBackground(Color.red);
    b1.setForeground(Color.white);
    b2.setBackground(Color.green);
    b2.setForeground(Color.white);*/
    b1.addActionListener(this);
    b2.addActionListener(this);
    fr.addWindowListener(new WindowAdapter()
    {
    public void WindowClosing(WindowEvent we)
    {
    System.exit(0);
    }
    });
    fr.add(b1);
    fr.add(b2);
    fr.add(l);
    fr.setSize(800,800);
    fr.setVisible(true);
    }
    //Image img[]=new Image[3];
    //TestFrame tf=new TestFrame("TestFrame");
    public static void main(String args[])
    {
    TestFrame tf=new TestFrame("TestFrame");
    tf.img[0]=Toolkit.getDefaultToolkit().getImage(args[0]);
    tf.img[1]=Toolkit.getDefaultToolkit().getImage(args[1]);
    tf.img[2]=Toolkit.getDefaultToolkit().getImage(args[2]);
    }
    public void actionPerformed(ActionEvent ae)
    {
    if(ae.getSource()==b1&&i<3)
    {
    repaint();
    i++;
    }
    else
    {
    repaint();
    i--;
    }
    }
    public void paint(Graphics g)
    {
    TestFrame te=new TestFrame();
    g.drawImage(te.img[i],300,50,200,200,this);
    }
    }
    Last edited by bigo005; 04-04-2014 at 10:55 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,813
    Rep Power
    25

    Default Re: Nothing except Frame and label shows up.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: 04-12-2013, 07:33 AM
  2. Replies: 4
    Last Post: 01-18-2011, 09:22 AM
  3. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  4. Replies: 7
    Last Post: 11-02-2009, 07:31 PM
  5. JTable in Frame only shows 3 rows
    By Laura Warren in forum New To Java
    Replies: 4
    Last Post: 12-24-2008, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •