-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction4.java
More file actions
132 lines (112 loc) · 3.13 KB
/
Function4.java
File metadata and controls
132 lines (112 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Timestamp;
import java.io.*;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.LineUnavailableException;
public class Function4 extends JPanel implements Runnable, MouseListener, MouseMotionListener
{
private int width, height;
private Thread runner;
private int x;
private int y;
public Function4()
{
width = 1000;
height = 1000;
setBackground(Color.white);
addMouseListener(this);
addMouseMotionListener(this);
if(runner == null)
{
runner = new Thread(this);
runner.start();
}
}
@Override
public void run()
{
}
@Override
public void mouseClicked(MouseEvent e)
{
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
@Override
public void mousePressed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e)
{
}
@Override
public void mouseMoved(MouseEvent e)
{
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
int x = (int) e.getX();
int y = (int) e.getY();
long t = timestamp.getTime();
double function = x - ( y);
if (y>0 && y<1000 && x>0 && x<1000) {
Sound wavefunction = new Sound();
try {
Sound.createTone((((function+400))), 100, 10000);
} catch (LineUnavailableException lue) {
System.out.println(lue);
}
System.out.println(x + "," + y + "," + t);
}
else {
System.out.println("Move your cursor closer to the graph");
}
}
@Override
public void mouseDragged(MouseEvent e)
{
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.black);
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3));
g2.drawLine(0, 500, 1000, 500);
g2.drawLine(500,0, 500, 1000);
g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g.drawString("1", 600, 500);
g.drawString("2", 700, 500);
g.drawString("3", 800, 500);
g.drawString("4", 900, 500);
g.drawString("5", 1000, 500);
g.drawString("-1", 400, 500);
g.drawString("-2", 300, 500);
g.drawString("-3", 200, 500);
g.drawString("-4", 100, 500);
g.drawString("-5", 0, 500);
g.drawString("1", 500, 400);
g.drawString("2", 500, 300);
g.drawString("3", 500, 200);
g.drawString("4", 500, 100);
g.drawString("5", 500, 0);
g.drawString("-1", 500, 600);
g.drawString("-2", 500, 700);
g.drawString("-3", 500, 800);
g.drawString("-4", 500, 900);
g.drawString("-5", 500, 1000);
}
}