hell + gui
This commit is contained in:
parent
4a63c7c01e
commit
b05b7cd13c
9 changed files with 212 additions and 3 deletions
|
@ -9,6 +9,9 @@ import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import userInterface.UserInterface;
|
||||||
|
import universe.*;
|
||||||
|
|
||||||
public class AppLaser {
|
public class AppLaser {
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
|
|
||||||
|
@ -312,7 +315,8 @@ public class AppLaser {
|
||||||
} while (choice != 0);
|
} while (choice != 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("there is no GUI yet.");
|
UserInterface userInterface= new UserInterface();
|
||||||
|
userInterface.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
makefile
4
makefile
|
@ -5,3 +5,7 @@ build:
|
||||||
run:
|
run:
|
||||||
javac --source 1.8 --target 1.8 AppLaser.java
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
java AppLaser -cli --optimize-duration
|
java AppLaser -cli --optimize-duration
|
||||||
|
|
||||||
|
run_gui:
|
||||||
|
javac --source 1.8 --target 1.8 AppLaser.java
|
||||||
|
java AppLaser
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
13
|
13
|
||||||
20
|
20
|
||||||
11
|
10
|
||||||
1
|
9
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
6
|
6
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// Antoine CRETUAL, Lukian LEIZOUR, 21/02/2024
|
// Antoine CRETUAL, Lukian LEIZOUR, 21/02/2024
|
||||||
|
|
||||||
|
package universe;
|
||||||
|
|
||||||
public class Situation {
|
public class Situation {
|
||||||
// Atributes
|
// Atributes
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// Antoine CRETUAL, Lukian LEIZOUR, 21/02/2024
|
// Antoine CRETUAL, Lukian LEIZOUR, 21/02/2024
|
||||||
|
|
||||||
|
package universe;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class Stack <T> {
|
public class Stack <T> {
|
|
@ -1,5 +1,7 @@
|
||||||
// Antoine CRETUAL, Lukian LEIZOUR, 14/02/2024
|
// Antoine CRETUAL, Lukian LEIZOUR, 14/02/2024
|
||||||
|
|
||||||
|
package universe;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
|
103
userInterface/Grid.java
Normal file
103
userInterface/Grid.java
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
package userInterface;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class Grid extends JPanel {
|
||||||
|
private int rows;
|
||||||
|
private int cols;
|
||||||
|
private Color[][] colors;
|
||||||
|
|
||||||
|
public Grid(int rows, int cols) {
|
||||||
|
this.rows = rows;
|
||||||
|
this.cols = cols;
|
||||||
|
setPreferredSize(new Dimension(400, 400));
|
||||||
|
setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
colors = new Color[rows][cols];
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < cols; j++) {
|
||||||
|
colors[i][j] = Color.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
int cellWidth = getWidth() / cols;
|
||||||
|
int cellHeight = getHeight() / rows;
|
||||||
|
int col = evt.getX() / cellWidth;
|
||||||
|
int row = evt.getY() / cellHeight;
|
||||||
|
|
||||||
|
if (row >= 0 && row < rows && col >= 0 && col < cols) {
|
||||||
|
if (colors[row][col] == Color.WHITE) {
|
||||||
|
colors[row][col] = Color.RED;
|
||||||
|
} else {
|
||||||
|
colors[row][col] = Color.WHITE;
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
try {
|
||||||
|
// Charger l'image pour le curseur personnalisé
|
||||||
|
BufferedImage cursorImage = ImageIO.read(new File("h:\\Mes documents\\INF1404\\projet\\picture\\sabre.png"));
|
||||||
|
// Créer le curseur personnalisé
|
||||||
|
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "customCursor");
|
||||||
|
// Définir le curseur personnalisé
|
||||||
|
setCursor(customCursor);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
setCursor(Cursor.getDefaultCursor()); // Rétablir l'icône de la souris par défaut quand elle quitte le composant
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
int cellWidth = getWidth() / cols;
|
||||||
|
int cellHeight = getHeight() / rows;
|
||||||
|
|
||||||
|
// Dessiner les cases avec les couleurs stockées
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < cols; j++) {
|
||||||
|
g.setColor(colors[i][j]);
|
||||||
|
g.fillRect(j * cellWidth, i * cellHeight, cellWidth, cellHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dessiner les lignes de la grille
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
for (int i = 0; i <= rows; i++) {
|
||||||
|
g.drawLine(0, i * cellHeight, getWidth(), i * cellHeight);
|
||||||
|
}
|
||||||
|
for (int j = 0; j <= cols; j++) {
|
||||||
|
g.drawLine(j * cellWidth, 0, j * cellWidth, getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
userInterface/UserInterface.java
Normal file
12
userInterface/UserInterface.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package userInterface;
|
||||||
|
|
||||||
|
public class UserInterface extends Thread {
|
||||||
|
private Window window;
|
||||||
|
|
||||||
|
public UserInterface() {
|
||||||
|
window = new Window();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
}
|
||||||
|
}
|
80
userInterface/Window.java
Normal file
80
userInterface/Window.java
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
package userInterface;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class Window extends JFrame {
|
||||||
|
|
||||||
|
JPanel panel;
|
||||||
|
JMenuBar menuBar;
|
||||||
|
Grid grid;
|
||||||
|
|
||||||
|
public Window() {
|
||||||
|
super("Laser Finder");
|
||||||
|
|
||||||
|
panel = new JPanel();
|
||||||
|
panel.setPreferredSize(new Dimension(1000,800));
|
||||||
|
panel.setBackground(Color.decode("#EBEBD3"));
|
||||||
|
|
||||||
|
|
||||||
|
menuBar = new JMenuBar();
|
||||||
|
|
||||||
|
JMenu fichierMenu = new JMenu("Fichier");
|
||||||
|
JMenu aideMenu = new JMenu("Aide");
|
||||||
|
|
||||||
|
ImageIcon nouveauIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\nouveau.png");
|
||||||
|
ImageIcon openIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\ouvrir.png");
|
||||||
|
ImageIcon saveIcon = new ImageIcon("h:\\Mes documents\\INF1404\\projet\\picture\\sauvegarder.png");
|
||||||
|
|
||||||
|
JMenuItem nouveauItem = new JMenuItem("Nouveau", nouveauIcon);
|
||||||
|
JMenuItem ouvrirItem = new JMenuItem("Ouvrir", openIcon);
|
||||||
|
JMenuItem enregistrerItem = new JMenuItem("Enregistrer", saveIcon);
|
||||||
|
|
||||||
|
JMenuItem apropos = new JMenuItem("à propos");
|
||||||
|
JMenuItem regles = new JMenuItem("règles");
|
||||||
|
|
||||||
|
fichierMenu.add(nouveauItem);
|
||||||
|
fichierMenu.add(ouvrirItem);
|
||||||
|
fichierMenu.add(enregistrerItem);
|
||||||
|
|
||||||
|
aideMenu.add(apropos);
|
||||||
|
aideMenu.add(regles);
|
||||||
|
|
||||||
|
menuBar.add(fichierMenu);
|
||||||
|
menuBar.add(aideMenu);
|
||||||
|
|
||||||
|
|
||||||
|
regles.addActionListener(e -> {
|
||||||
|
JOptionPane.showMessageDialog(this, "Définissez la taille du plateau ainsi que l'orientation du laser, enfin ajoutez des obstacles et laissez le programme trouver le bon chemin !");
|
||||||
|
});
|
||||||
|
|
||||||
|
grid = new Grid(5, 5);
|
||||||
|
panel.add(grid, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
super.setJMenuBar(menuBar);
|
||||||
|
super.setContentPane(this.panel);
|
||||||
|
|
||||||
|
super.setLocationRelativeTo(null);
|
||||||
|
super.setLocation(1000, 400);
|
||||||
|
super.pack();
|
||||||
|
super.setVisible(true);
|
||||||
|
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue