| |

VerySource

 Forgot password?
 Register
Search
View: 735|Reply: 2

Display image on local disk on jpanel?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 11:20:01
| Show all posts |Read mode
How to use Graphics.drawImage () on Jpanel to display the image on the local disk? Thank you
Reply

Use magic Report

1

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-5 15:45:01
| Show all posts
import java.awt. *;
import java.awt.event. *;
import javax.swing. *;

public class Test extends Frame
{

    public Test ()
    {
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
dispose ();
System.exit (0);
}
});
    }

    public static void main (String args [])
    {
Test mainFrame = new Test ();
JPanel jpanel = new JPanel ();
Image img = mainFrame.getToolkit (). GetImage ("c:\\bag.png");
mainFrame.add (jpanel);
mainFrame.setSize (400, 400);
mainFrame.setTitle ("DrawImage");
mainFrame.setVisible (true);
Graphics g = jpanel.getGraphics ();
while (! g.drawImage (img, 100, 100, mainFrame));
System.out.println ("Start Drawing!");
    }
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Switzerland

 Author| Post time: 2020-1-6 19:00:01
| Show all posts
Brothers upstairs, can I only open png images? I have debugged and can't display the images.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list