NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Thursday;

/**
*
* @author admin
*/
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MouseTrackerFrame extends JFrame {

private final JPanel mousePanel;
private final JLabel statusBar;

public MouseTrackerFrame() {
super("Demonstrating Mouse Events");

mousePanel = new JPanel();
mousePanel.setBackground(Color.WHITE);
add(mousePanel, BorderLayout.CENTER);

statusBar = new JLabel("Mouse outside JPanel");
add(statusBar, BorderLayout.SOUTH);

MouseHandler handler = new MouseHandler();
mousePanel.addMouseListener(handler);
mousePanel.addMouseMotionListener(handler);
}

private class MouseHandler implements MouseListener, MouseMotionListener {

@Override
public void mouseClicked(MouseEvent event) {
statusBar.setText(String.format("Clicked at [%d, %d]",
event.getX(), event.getY()));
}

@Override
public void mousePressed(MouseEvent event) {
statusBar.setText(String.format("Pressed at [%d, %d]",
event.getX(), event.getY()));
}

@Override
public void mouseReleased(MouseEvent event) {
statusBar.setText(String.format("Released at [%d, %d]",
event.getX(), event.getY()));
}

@Override
public void mouseEntered(MouseEvent event) {
statusBar.setText(String.format("Mouse entered at [%d, %d]",
event.getX(), event.getY()));
mousePanel.setBackground(Color.GREEN);
}

@Override
public void mouseExited(MouseEvent event) {
statusBar.setText("Mouse outside JPanel");
mousePanel.setBackground(Color.WHITE);
}
}
}






import javax.swing.JFrame;

public class MouseTracker {

public static void main(String[] args) {
MouseTrackerFrame mouseTrackerFrame = new MouseTrackerFrame();
mouseTrackerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mouseTrackerFrame.setSize(300, 100);
mouseTrackerFrame.setVisible(true);
}
}






/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Thursday;

/**
*
* @author admin
*/
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class MouseDetailsFrame extends JFrame {

private String details;
private final JLabel statusBar;

public MouseDetailsFrame() {
super("Mouse clicks and buttons");

statusBar = new JLabel("Click the mouse");
add(statusBar, BorderLayout.SOUTH);
addMouseListener(new MouseClickHandler());
}

private class MouseClickHandler extends MouseAdapter {

@Override
public void mouseClicked(MouseEvent event) {
int xPos = event.getX();
int yPos = event.getY();

details = String.format("Clicked %d time(s)", event.getClickCount());

if (event.isMetaDown()) {
details += " with right mouse button";
} else if (event.isAltDown()) {
details += " with center mouse button";
} else {
details += " with left mouse button";
}

statusBar.setText(details);
}
}
}





/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Thursday;

/**
*
* @author admin
*/
import javax.swing.JFrame;

public class MouseDetails {

public static void main(String[] args) {
MouseDetailsFrame mouseDetailsFrame = new MouseDetailsFrame();
mouseDetailsFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mouseDetailsFrame.setSize(400, 150);
mouseDetailsFrame.setVisible(true);
}

}



/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Thursday;

/**
*
* @author admin
*/
import java.awt.Point;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import javax.swing.JPanel;

public class PaintPanel extends JPanel {

private final ArrayList<Point> points = new ArrayList<>();

public PaintPanel() {
addMouseMotionListener(
new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent event) {
points.add(event.getPoint());
repaint();

}
}
);
}

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);

for (Point point : points) {
g.fillOval(point.x, point.y, 4, 4);
}
}
}





/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Thursday;

/**
*
* @author admin
*/
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Painter {

public static void main(String[] args) {
JFrame application = new JFrame("A simple paint program");
PaintPanel paintPanel = new PaintPanel();

application.add(paintPanel, BorderLayout.CENTER);

application.add(new JLabel("Drag the mouse to draw"),
BorderLayout.SOUTH);

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setSize(400, 200);
application.setVisible(true);
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.