Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.KeyEventDispatcher;
- import java.awt.KeyboardFocusManager;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class main {
- public static Viewer v;
- public static Console c;
- public static void main(String[] args) {
- v=new Viewer();
- c=new Console();
- }
- static class Viewer extends JFrame {
- public Viewer(){
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(600,600);
- getContentPane().add(new myPanel());
- addMouseListener(new mouse());
- setVisible(true);
- }
- }
- static class myPanel extends JPanel{
- public void paintComponent(Graphics g){
- g.setColor(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255)));
- g.fillRect(0, 0, 600, 600);
- }
- }
- static class Console extends JFrame {
- public Console(){
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(600,200);
- JTextField text=new JTextField();
- getContentPane().add(text);
- setVisible(true);
- KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
- new KeyEventDispatcher(){
- @Override
- public boolean dispatchKeyEvent(KeyEvent e) {
- //What now?
- return false;
- }
- }
- );
- }
- }
- static class mouse implements MouseListener{
- @Override
- public void mouseClicked(MouseEvent arg0) {
- v.repaint();
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement