Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hw11;
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.util.Random;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- class MyPainter extends JPanel implements ActionListener, MouseListener {
- JButton b1, b2, b3, b4, b5, b6,
- b7, b8, b9, b10, b11, b12,
- b13, b14, b15, b16, b17, b18;
- String s1, s2, s3, s4, s5, s6,
- s7, s8, s9, s10, s11, s12,
- s13, s14, s15, s16, s17, s18;
- boolean k = false;
- MyPainter() {
- //setBackground(Color.GRAY);
- setLayout(null);
- addMouseListener(this);
- s1 = "h";
- b1 = new JButton();
- b1.setBounds(16, 48, 48, 48);
- b1.setFocusable(true);
- add(b1);
- b1.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- Graphics g = getGraphics();
- if(e.getSource() == b1) {
- g.drawString(s1, 40, 72);
- }
- // if (e.getSource() == bRed)
- // drawColor = Color.RED;
- // else if (e.getSource() == bBlue)
- // drawColor = Color.BLUE;
- // else if (e.getSource() == bLine)
- // drawShape = 'l';
- // else if (e.getSource() == bCircle)
- // drawShape = 'c';
- }
- public void mousePressed(MouseEvent e) {
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseClicked(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void mouseExited(MouseEvent e) {
- }
- }
- public class Hw11 {
- public static void main(String[] args) {
- JFrame myWin = new JFrame("My Painter");
- MyPainter mC = new MyPainter();
- myWin.add(mC);
- myWin.setSize(800, 600);
- myWin.setLocation(100, 50);
- myWin.setVisible(true);
- myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
- //
- //class Game extends JFrame implements ActionListener, MouseListener, MouseMotionListener {
- // JButton b1, b2, b3, b4, b5, b6,
- // b7, b8, b9, b10, b11, b12,
- // b13, b14, b15, b16, b17, b18;
- //
- // String s1, s2, s3, s4, s5, s6,
- // s7, s8, s9, s10, s11, s12,
- // s13, s14, s15, s16, s17, s18;
- //
- //
- //
- // Game() {
- //// setLayout(null);
- //// addMouseListener(this);
- //// addMouseMotionListener(this);
- ////
- //// b1 = new JButton();
- //// b1.setBounds(0, 48, 48, 48);
- //// b1.setFocusable(false);
- //// add(b1);
- //// b1.addActionListener(this);
- ////
- // }
- //
- // public void actionPerformed(ActionEvent e) {
- //// if (e.getSource() == bRed)
- //// drawColor = Color.RED;
- //// else if (e.getSource() == bBlue)
- //// drawColor = Color.BLUE;
- //// else if (e.getSource() == bLine)
- //// drawShape = 'l';
- //// else if (e.getSource() == bCircle)
- //// drawShape = 'c';
- //
- // }
- //
- // void Create(int c) {
- // s1 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s2 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s3 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s4 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s5 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s6 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s7 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s8 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s9 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s10 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s11 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s12 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s13 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s14 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s15 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s16 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s17 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s18 = ""+(char)c;
- // c--;
- // }
- //
- //
- //
- //
- // public void mousePressed(MouseEvent e) {
- //
- // }
- //
- // public void mouseReleased(MouseEvent e) {
- //
- // }
- //
- // public void mouseClicked(MouseEvent e) {
- //
- // }
- //
- // public void mouseEntered(MouseEvent e) {
- //
- // }
- //
- // public void mouseExited(MouseEvent e) {
- //
- // }
- //
- // public void mouseMoved(MouseEvent e) {
- //
- // }
- //
- // public void mouseDragged(MouseEvent e) {
- //
- // }
- //
- //}
- //
- //
- //public class Hw11 extends JPanel {
- //
- //
- // public void paint(Graphics g) {
- //
- //
- // }
- //
- // public static void main(String[] args) {
- //// JFrame frame = new JFrame();
- //// frame.getContentPane().add(new Hw11());
- ////
- //// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //// frame.setSize(500,500);
- //// frame.setVisible(true);
- ////
- //// Random rnd = new Random();
- //// int c = ('r'-rnd.nextInt(19));
- ////
- //// Game gm = new Game();
- //// gm.Create(c);
- ////
- // JFrame myWin = new JFrame("My Painter");
- //
- // Game mC = new Game();
- //
- // myWin.add(mC);
- // myWin.setSize(800, 600);
- // myWin.setLocation(100, 50);
- // myWin.setVisible(true);
- // myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // Random rnd = new Random();
- // int c = ('r'-rnd.nextInt(19));
- //
- // Game gm = new Game();
- // gm.Create(c);
- //
- //
- //s1 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s2 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s3 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s4 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s5 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s6 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s7 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s8 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s9 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s10 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s11 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s12 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s13 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s14 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s15 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s16 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s17 = ""+(char)c;
- // c--;
- // if(c < 97)
- // c = c+'r'-'a'+1;
- // s18 = ""+(char)c;
- // c--;
- //
- //
- // System.out.println(s1);
- // System.out.println(s2);
- // System.out.println(s3);
- // System.out.println(s4);
- // System.out.println(s5);
- // System.out.println(s6);
- // System.out.println(s7);
- // System.out.println(s8);
- // System.out.println(s9);
- // System.out.println(s10);
- // System.out.println(s11);
- // System.out.println(s12);
- // System.out.println(s13);
- // System.out.println(s14);
- // System.out.println(s15);
- // System.out.println(s16);
- // System.out.println(s17);
- // System.out.println(s18);
- //
- // int c = ('r'-rnd.nextInt(19));
- // if(c < 'a' - 0)
- // c = 'a' + c + 1;
- //
- // System.out.println((char)c);
- //
- // System.out.println();
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement