Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ComponentEvent;
- public class PaintTest extends JFrame{
- private JPanel panel1;
- private JButton button1;
- private JRadioButton radioButton1;
- private JRadioButton radioButton2;
- public PaintTest() {
- super("Hello World");
- setContentPane(panel1);
- pack();
- setDefaultLookAndFeelDecorated(false);
- setMinimumSize(new Dimension(300,300) );
- setResizable(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- update(panel1.getGraphics());
- }
- });
- }
- @Override
- public void update(Graphics g){
- paintComponent(g);
- }
- protected void paintComponent(Graphics g)
- {
- super.paintComponents(g);
- Graphics2D g2d = (Graphics2D)g;
- g2d.setColor(Color.yellow);
- g2d.fillRect(30, 30, 100, 100);
- g2d.drawLine(0,0, 200,200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement