Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab3;
- import java.awt.Graphics;
- import javax.swing.JPanel;
- public class MyPanel extends JPanel {
- private int figureType = 0;
- public void setFigureType(int fType) {
- figureType = fType;
- repaint();
- }
- public void paint(Graphics g) {
- super.paint(g);
- if (figureType == 0) {
- g.drawRect(0+20, 20, 40, 40);
- g.drawLine(0+15, 20, 20+20, 0);
- g.drawLine(20+20, 00, 45+20, 20);
- g.drawLine(15, 20, 45+20, 20);
- g.drawLine(30+20, 8, 30+20, 00);
- g.drawLine(30+20, 00, 40+20, 00);
- g.drawLine(40+20, 00, 40+20, 16);
- } else {
- for(int i = 0,j = 0; i <= 100;i += 10,j += 10) {
- g.drawLine(20, 120-j, 200, 20+i);
- }
- }
- }
- }
- package lab3;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import javax.swing.border.BevelBorder;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class lab4 {
- private JFrame frame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- lab4 window = new lab4();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public lab4() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- MyPanel panel = new MyPanel();
- panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
- panel.setBounds(0, 0, 316, 261);
- frame.getContentPane().add(panel);
- JButton btnNewButton = new JButton("\u0414\u043E\u043C");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- panel.setFigureType(0);
- }
- });
- btnNewButton.setBounds(335, 11, 89, 23);
- frame.getContentPane().add(btnNewButton);
- JButton btnNewButton_1 = new JButton("\u041B\u0438\u043D\u0438\u0438");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- panel.setFigureType(1);
- }
- });
- btnNewButton_1.setBounds(335, 56, 89, 23);
- frame.getContentPane().add(btnNewButton_1);
- }
- }
Add Comment
Please, Sign In to add comment