Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Polowienie;
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- import javax.swing.JPanel;
- public class ObrazPanel extends JPanel {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private BufferedImage image;
- public ObrazPanel() {
- super();
- File imageFile = new File("G:\\wykres.jpg");
- try {
- image = ImageIO.read(imageFile);
- } catch (IOException e) {
- System.err.println("Blad odczytu obrazka");
- e.printStackTrace();
- }
- Dimension dimension = new Dimension(image.getWidth(), image.getHeight());
- setPreferredSize(dimension);
- }
- @Override
- public void paintComponent(Graphics g) {
- Graphics2D g2d = (Graphics2D) g;
- g2d.drawImage(image, 0, 0, this);
- }
- }
- package Polowienie;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class ObrazFrame extends JFrame {
- public ObrazFrame() {
- super("Program obrazkowy");
- JPanel obrazPanel = new ObrazPanel();
- add(obrazPanel);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- pack();
- setVisible(true);
- }
- }
- package Polowienie;
- import java.awt.EventQueue;
- public class Test {
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new ObrazFrame();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment