Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java JFrame size and centre
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- public class DiceSimulator {
- public static void main(String[] args) {
- JFrame frame = new JFrame("DiceSimulator");
- frame.setVisible(true);
- frame.setSize(400, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- draw object = new draw();
- frame.add(object);
- frame.setLocationRelativeTo(null);
- object.drawing();
- }
- }
- import javax.swing.*;
- import java.awt.*;
- //import java.util.Random;
- public class draw extends JComponent {
- public void drawing() {
- repaint();
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- //Random1 random = new Random1();
- Graphics2D g2 = (Graphics2D) g;
- g.setColor(Color.BLACK);
- Rectangle box = new Rectangle(115, 60, 150, 150);
- g2.fill(box);
- g.setColor(Color.WHITE);
- g.fillOval(145, 75, 30, 30);
- g.setColor(Color.WHITE);
- g.fillOval(205, 75, 30, 30);
- g.setColor(Color.WHITE);
- g.fillOval(145, 115, 30, 30);
- g.setColor(Color.WHITE);
- g.fillOval(205, 115, 30, 30);
- g.setColor(Color.WHITE);
- g.fillOval(145, 155, 30, 30);
- g.setColor(Color.WHITE);
- g.fillOval(205, 155, 30, 30);
- }
- }
- int width = getSize().width;
- int height = getSize().height;
- g.translate(5, 5);
Add Comment
Please, Sign In to add comment