Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 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.  
  6. public class MojeOkno extends JFrame {
  7.     private JButton button;
  8.     private JLabel jLabel;
  9.     private Point point;
  10.     MojeOkno()
  11.     {
  12.         super("Okno");
  13.         this.setLayout(new FlowLayout());
  14.         button = new JButton();
  15.         button.setSize(100,100);
  16.         button.setText("Elo witam");
  17.         point = new Point();
  18.  
  19.         button.addActionListener(new ActionListener() {
  20.             @Override
  21.             public void actionPerformed(ActionEvent e) {
  22.                 System.out.println("elo tutaj po kliknieciu buttona");
  23.             }
  24.         });
  25.  
  26.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.         setSize(800,800);
  28.         this.add(button);
  29.         this.add(point);
  30.         setVisible(true);
  31.     }
  32. }
  33.  
  34.  
  35. import java.awt.*;
  36.  
  37. public class Main {
  38.  
  39.     public static void main(String[] args) {
  40.  
  41.         EventQueue.invokeLater(new Runnable() {
  42.             @Override
  43.             public void run() {
  44.                 new MojeOkno();
  45.             }
  46.         });
  47.  
  48.  
  49.     }
  50. }
  51. import java.awt.Color;
  52. import java.awt.Dimension;
  53. import java.awt.Graphics;
  54. import java.awt.Graphics2D;
  55. import java.util.Random;
  56. import javax.swing.JPanel;
  57.  
  58. public class Point extends JPanel {
  59.  
  60.     public Point() {
  61.         setPreferredSize(new Dimension(200, 200));
  62.     }
  63.  
  64.     @Override
  65.     public void paintComponent(Graphics g) {
  66.         super.paintComponent(g);
  67.  
  68.         Graphics2D g2d = (Graphics2D) g;
  69.  
  70.         g2d.setColor(Color.red);
  71.         g2d.fillRect(100,100,10,10);
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement