cleaned the repo
This commit is contained in:
97
ImageToText/src/Image.java
Normal file
97
ImageToText/src/Image.java
Normal file
@@ -0,0 +1,97 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Image extends Canvas {
|
||||
|
||||
private JFrame frame;
|
||||
private BufferedImage img;
|
||||
private Color c;
|
||||
private File f;
|
||||
private ArrayList<File> files;
|
||||
private static int n;
|
||||
private KeyListener keys;
|
||||
|
||||
public Image() {
|
||||
f = new File("/home/bitecoding/Bilder");
|
||||
files = new ArrayList<File>(Arrays.asList(f.listFiles()));
|
||||
c = null;
|
||||
n = 0;
|
||||
|
||||
try {
|
||||
img = ImageIO.read(files.get(0));
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
||||
keys = new KeyListener() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyChar() == ' '){
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
frame = new JFrame();
|
||||
frame.setSize(img.getWidth(), img.getHeight());
|
||||
frame.addKeyListener(keys);
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
|
||||
try {
|
||||
img = ImageIO.read(files.get(n%2));
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
c = new Color(img.getRGB(x, y), true);
|
||||
g2d.setColor(c);
|
||||
g2d.drawLine(x, y, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
Image image = new Image();
|
||||
image.frame.add(image);
|
||||
|
||||
int temp = 0;
|
||||
while (true){
|
||||
Thread.sleep(1);
|
||||
if (temp != n){
|
||||
image.repaint();
|
||||
temp = n;
|
||||
System.out.println(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Keyboard {
|
||||
|
||||
public static void main(String args[]) throws InterruptedException {
|
||||
KeyListener listener = new KeyListener() {
|
||||
|
||||
@Override
|
||||
|
||||
public void keyPressed(KeyEvent event) {
|
||||
System.out.println(event.getKeyChar());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
System.out.println(event.getKeyChar());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void keyTyped(KeyEvent event) {
|
||||
System.out.println(event.getKeyChar());
|
||||
}
|
||||
|
||||
private void printEventInfo(String str, KeyEvent e) {
|
||||
System.out.println(str);
|
||||
int code = e.getKeyCode();
|
||||
System.out.println(" Code: " + KeyEvent.getKeyText(code));
|
||||
System.out.println(" Char: " + e.getKeyChar());
|
||||
int mods = e.getModifiersEx();
|
||||
System.out.println(" Mods: "
|
||||
+ KeyEvent.getModifiersExText(mods));
|
||||
System.out.println(" Location: "
|
||||
+ keyboardLocation(e.getKeyLocation()));
|
||||
System.out.println(" Action? " + e.isActionKey());
|
||||
}
|
||||
|
||||
private String keyboardLocation(int keybrd) {
|
||||
switch (keybrd) {
|
||||
case KeyEvent.KEY_LOCATION_RIGHT:
|
||||
return "Right";
|
||||
case KeyEvent.KEY_LOCATION_LEFT:
|
||||
return "Left";
|
||||
case KeyEvent.KEY_LOCATION_NUMPAD:
|
||||
return "NumPad";
|
||||
case KeyEvent.KEY_LOCATION_STANDARD:
|
||||
return "Standard";
|
||||
case KeyEvent.KEY_LOCATION_UNKNOWN:
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
JFrame jFrame = new JFrame();
|
||||
jFrame.setSize(1000,1000);
|
||||
jFrame.setVisible(true);
|
||||
|
||||
jFrame.addKeyListener(listener);
|
||||
|
||||
while(true){
|
||||
Thread.sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package src;
|
||||
|
||||
import org.w3c.dom.css.RGBColor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class Test extends Frame implements ActionListener {
|
||||
private Label lblCount; // Declare a Label component
|
||||
private TextField tfCount; // Declare a TextField component
|
||||
private Button btnCount; // Declare a Button component
|
||||
private int count = 0; // Counter's value
|
||||
private Color c;
|
||||
|
||||
// Constructor to setup GUI components and event handlers
|
||||
public Test () {
|
||||
setLayout(new FlowLayout());
|
||||
// "super" Frame, which is a Container, sets its layout to FlowLayout to arrange
|
||||
// the components from left-to-right, and flow to next row from top-to-bottom.
|
||||
|
||||
lblCount = new Label("Counter"); // construct the Label component
|
||||
add(lblCount); // "super" Frame container adds Label component
|
||||
|
||||
tfCount = new TextField(count + "", 5); // construct the TextField component with initial text
|
||||
tfCount.setEditable(false); // set to read-only
|
||||
add(tfCount); // "super" Frame container adds TextField component
|
||||
|
||||
btnCount = new Button("Count"); // construct the Button component
|
||||
add(btnCount); // "super" Frame container adds Button component
|
||||
|
||||
btnCount.addActionListener(this);
|
||||
// "btnCount" is the source object that fires an ActionEvent when clicked.
|
||||
// The source add "this" instance as an ActionEvent listener, which provides
|
||||
// an ActionEvent handler called actionPerformed().
|
||||
// Clicking "btnCount" invokes actionPerformed().
|
||||
|
||||
setTitle("AWT Counter"); // "super" Frame sets its title
|
||||
setSize(250, 100); // "super" Frame sets its initial window size
|
||||
|
||||
// For inspecting the Container/Components objects
|
||||
// System.out.println(this);
|
||||
// System.out.println(lblCount);
|
||||
// System.out.println(tfCount);
|
||||
// System.out.println(btnCount);
|
||||
|
||||
setVisible(true); // "super" Frame shows
|
||||
|
||||
c = new Color(150,100,25);
|
||||
// System.out.println(this);
|
||||
// System.out.println(lblCount);
|
||||
// System.out.println(tfCount);
|
||||
// System.out.println(btnCount);
|
||||
}
|
||||
|
||||
// The entry main() method
|
||||
public static void main(String[] args) {
|
||||
// Invoke the constructor to setup the GUI, by allocating an instance
|
||||
Test app = new Test();
|
||||
// or simply "new AWTCounter();" for an anonymous instance
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
++count; // Increase the counter value
|
||||
// Display the counter value on the TextField tfCount
|
||||
tfCount.setText(count + ""); // Convert int to String
|
||||
System.out.println(c.getRGB());
|
||||
c = c.brighter();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
public class Text{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user