Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
JAVA/CPP repo for OPENHACK.
# Simple Text Editor

This is a simple text editor application created using Java Swing.

## Features

- Create new text files.
- Open existing text files.
- Save text files.
- Print text files.
- Cut, copy, and paste text.
- Close files.

## How to Run

1. Ensure you have Java installed on your PC. If not, download and install Java from [here](https://www.java.com/en/download/).
2. Download the `editor.java` file from this repository.
3. Open Command Prompt (on Windows) or Terminal (on macOS/Linux).
4. Navigate to the directory where the `editor.java` file is located.
5. Compile the Java source file using the following command:
```bash
javac editor.java
```
6. Run the compiled Java program using the following command:
```bash
java editor
```

## Usage

- **Creating a New File**: Click on the "File" menu and select "New".
- **Opening an Existing File**: Click on the "File" menu and select "Open".
- **Saving a File**: Click on the "File" menu and select "Save".
- **Printing a File**: Click on the "File" menu and select "Print".
- **Editing Operations**: Use the "Edit" menu for cut, copy, and paste operations.
- **Cutting Text**: Select the text you want to cut, then click on the "Edit" menu and select "Cut".
- **Copying Text**: Select the text you want to copy, then click on the "Edit" menu and select "Copy".
- **Pasting Text**: Place the cursor where you want to paste the text, then click on the "Edit" menu and select "Paste".
- **Closing a File**: Click on the "File" menu and select "Close" to close the current file window.

## Notes

- This text editor supports editing multiple text files simultaneously.
- The application uses Java Swing for the graphical user interface.

41 changes: 41 additions & 0 deletions READme(tic tac toe).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Tic Tac Toe Game

This is a simple Tic Tac Toe game implemented in Java with a graphical user interface (GUI). Players take turns marking spaces in a 3x3 grid, aiming to be the first to get three of their marks in a row.

## Features

- Graphical user interface built using Java Swing.
- Tracks player scores and displays winning ratios.
- Stores high scores in a MySQL database.
- Allows resetting of scores.
- Shows statistics of the game, including winning ratios for X and O players and draw ratios.

## Prerequisites

- Java Development Kit (JDK) installed on your system.
- MySQL database server set up and running.

## Usage

-Players take turns clicking on empty spaces in the grid to mark them with their symbol (X or O).
-The game tracks the scores of X and O players, as well as draw games.
-Click on the "Show Stats" menu item to display the winning ratios of X and O players, as well as the draw ratio.
-Click on the "High Scores" menu item to display the top scores stored in the database.
-Click on the "Reset Scores" button to clear all scores stored in the database.
-Enjoy playing Tic Tac Toe!

## Setup

1. Set up the MySQL database:

- Create a MySQL database named `tictactoe`.
- Create a table named `scores` with two columns: `player` (VARCHAR) and `wins` (INT).

2. Open the project in your Java IDE.

3. Add the MySQL JDBC driver to your project's dependencies. You can download the MySQL JDBC driver from [here](https://dev.mysql.com/downloads/connector/j/).

4. Update the MySQL connection details in the `TicTacToeGUI.java` file:

```java
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shubham", "root", "");
268 changes: 268 additions & 0 deletions Texteditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
// Java Program to create a text editor using java

import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.plaf.metal.*;

class Texteditor extends JFrame implements ActionListener {
// Text component

JTextArea t;
private JFrame[] frames;
private JTextArea[] textAreas;
private int numOpenFiles;

// Frame
JFrame f;

// Constructor
Texteditor() {
// Create a frame
f = new JFrame("editor");

try {
// Set metal look and feel
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

// Set theme to ocean
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
} catch (Exception e) {
}

// Text component
t = new JTextArea();
// Initialize arrays
frames = new JFrame[10]; // Assuming a maximum of 10 open files
textAreas = new JTextArea[10];
numOpenFiles = 0;

// Create a menubar
JMenuBar mb = new JMenuBar();

// Create amenu for menu
JMenu m1 = new JMenu("File");

// Create menu items
JMenuItem mi1 = new JMenuItem("New");
JMenuItem mi2 = new JMenuItem("Open");
JMenuItem mi3 = new JMenuItem("Save");
JMenuItem mi9 = new JMenuItem("Print");

// Add action listener
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi9.addActionListener(this);

m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi9);

// Create amenu for menu
JMenu m2 = new JMenu("Edit");

// Create menu items
JMenuItem mi4 = new JMenuItem("cut");
JMenuItem mi5 = new JMenuItem("copy");
JMenuItem mi6 = new JMenuItem("paste");

// Add action listener
mi4.addActionListener(this);
mi5.addActionListener(this);
mi6.addActionListener(this);

m2.add(mi4);
m2.add(mi5);
m2.add(mi6);

JMenuItem mc = new JMenuItem("close");

mc.addActionListener(this);

mb.add(m1);
mb.add(m2);
mb.add(mc);

f.setJMenuBar(mb);
f.add(t);
f.setSize(500, 500);
f.show();
}

// If a button is pressed
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();

if (s.equals("cut")) {
t.cut();
} else if (s.equals("copy")) {
t.copy();
} else if (s.equals("paste")) {
t.paste();
} else if (s.equals("Save")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");

// Invoke the showsSaveDialog function to show the save dialog
int r = j.showSaveDialog(null);

if (r == JFileChooser.APPROVE_OPTION) {

// Set the label to the path of the selected directory
File fi = new File(j.getSelectedFile().getAbsolutePath());

try {
// Create a file writer
FileWriter wr = new FileWriter(fi, false);

// Create buffered writer to write
BufferedWriter w = new BufferedWriter(wr);

// Write
w.write(t.getText());

w.flush();
w.close();
} catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
} // If the user cancelled the operation
else {
JOptionPane.showMessageDialog(f, "the user cancelled the operation");
}
} else if (s.equals("Print")) {
try {
// print the file
t.print();
} catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
} else if (s.equals("Open")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");

// Invoke the showsOpenDialog function to show the save dialog
int r = j.showOpenDialog(null);

// If the user selects a file
if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory
File fi = new File(j.getSelectedFile().getAbsolutePath());

try {
// String
String s1 = "", sl = "";

// File reader
FileReader fr = new FileReader(fi);

// Buffered reader
BufferedReader br = new BufferedReader(fr);

// Initialize sl
sl = br.readLine();

// Take the input from the file
while ((s1 = br.readLine()) != null) {
sl = sl + "\n" + s1;
}

// Set the text
t.setText(sl);
} catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
} // If the user cancelled the operation
else {
JOptionPane.showMessageDialog(f, "the user cancelled the operation");
}
} else if (s.equals("New")) {
t.setText("");
createNewFile();
} else if (s.equals("close")) {
f.setVisible(false);
}
}

private void createNewFile() {
JFrame frame = new JFrame("Untitled-" + (numOpenFiles + 1));
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
frame.add(scrollPane);

// Create a menubar
JMenuBar mb = new JMenuBar();

// Create a menu for File
JMenu m1 = new JMenu("File");

// Create menu items for File
JMenuItem mi1 = new JMenuItem("New");
JMenuItem mi2 = new JMenuItem("Open");
JMenuItem mi3 = new JMenuItem("Save");
JMenuItem mi9 = new JMenuItem("Print");

// Add action listeners to menu items
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi9.addActionListener(this);

// Add menu items to the File menu
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi9);

// Create a menu for Edit
JMenu m2 = new JMenu("Edit");

// Create menu items for Edit
JMenuItem mi4 = new JMenuItem("cut");
JMenuItem mi5 = new JMenuItem("copy");
JMenuItem mi6 = new JMenuItem("paste");

// Add action listeners to menu items
mi4.addActionListener(this);
mi5.addActionListener(this);
mi6.addActionListener(this);

// Add menu items to the Edit menu
m2.add(mi4);
m2.add(mi5);
m2.add(mi6);

// Create a menu item for Close
JMenuItem mc = new JMenuItem("close");

// Add action listener to the Close menu item
mc.addActionListener(this);

// Add File and Edit menus to the menubar
mb.add(m1);
mb.add(m2);

// Add Close menu item to the menubar
mb.add(mc);

// Set the menubar for the frame
frame.setJMenuBar(mb);

// Set frame size and visibility
frame.setSize(500, 500);
frame.setVisible(true);

// Store references to JFrame and JTextArea
frames[numOpenFiles] = frame;
textAreas[numOpenFiles] = textArea;
numOpenFiles++;
}


// Main class
public static void main(String args[]) {
Texteditor e = new Texteditor();
}
}
Loading