Advertisement
Guest User

Untitled

a guest
Sep 12th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ComponentEvent;
  6.  
  7. public class PaintTest extends JFrame{
  8.     private JPanel panel1;
  9.     private JButton button1;
  10.     private JRadioButton radioButton1;
  11.     private JRadioButton radioButton2;
  12.  
  13.  
  14.    public PaintTest() {
  15.        super("Hello World");
  16.  
  17.  
  18.        setContentPane(panel1);
  19.  
  20.        pack();
  21.        setDefaultLookAndFeelDecorated(false);
  22.        setMinimumSize(new Dimension(300,300) );
  23.        setResizable(true);
  24.        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.        setVisible(true);
  26.  
  27.        button1.addActionListener(new ActionListener() {
  28.            @Override
  29.            public void actionPerformed(ActionEvent e) {
  30.                update(panel1.getGraphics());
  31.            }
  32.  
  33.        });
  34.  
  35.  
  36.    }
  37.     @Override
  38.     public void update(Graphics g){
  39.         paintComponent(g);
  40.     }
  41.    
  42.     protected void paintComponent(Graphics g)
  43.     {
  44.         super.paintComponents(g);
  45.         Graphics2D g2d = (Graphics2D)g;
  46.  
  47.         g2d.setColor(Color.yellow);
  48.         g2d.fillRect(30, 30, 100, 100);
  49.         g2d.drawLine(0,0, 200,200);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement