Skip to content
Snippets Groups Projects
Commit 6aebfa0e authored by NGUYEN Duc duong's avatar NGUYEN Duc duong
Browse files

update GUI

parent a8feba11
No related branches found
No related tags found
No related merge requests found
Pipeline #18795 passed
......@@ -16,7 +16,7 @@ public class Building extends JPanel
private Elevator elevator1;
// private Elevator elevator2;
private List<Floor> floors;
private int nbFloor;
private static int nbFloor;
// private Random random;
......@@ -29,14 +29,14 @@ public class Building extends JPanel
*/
this.nbFloor = nbFloor;
elevator1 = new Elevator(100, 400);
elevator1 = new Elevator(100, Main.getPanelHeight()-heightFloor());
//elevator2 = new Elevator(250, 400);
floors = Collections.synchronizedList(new ArrayList());
for (int i = 0; i < nbFloor; i++)
{
floors.add(new Floor(100, 200, 250, 350, 100 * (nbFloor - i), 750, i));
floors.add(new Floor(100, 200, 250, 350, heightFloor() * (nbFloor - i), 750, i));
}
/* random = new Random();
......@@ -83,11 +83,13 @@ public class Building extends JPanel
}
}
*/
public int getNbFloor(){
public static int getNbFloor(){
return nbFloor;
}
public static int heightFloor(){
return Main.getPanelHeight()/getNbFloor();
}
@Override
......
......@@ -20,7 +20,7 @@ public class Elevator
public Elevator(int xAxis, int yAxis)
{
this(xAxis, yAxis, 100, 100, 0);
this(xAxis, yAxis, 100, Building.heightFloor(), 0);
}
public Elevator(int xAxis, int yAxis, int width, int height, int floor)
......@@ -48,11 +48,6 @@ public class Elevator
}
public int getFloor()
{
return this.floor;
......
/*
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Floor
{
private int x1;
private int x2;
private int x3;
private int x4;
private int y;
private int l;
private int floor;
public Floor(int x1, int x2, int x3, int x4, int y, int l, int floor)
{
this.x1 = x1;
this.x2 = x2;
this.x3 = x3;
this.x4 = x4;
this.y = y;
this.l = l;
this.floor = floor;
}
public void draw(Graphics g)
{
g.drawLine(0, y, x1, y);
g.drawLine(x2, y, x3, y);
g.drawLine(x4, y, x3,y);
g.setColor(Color.LIGHT_GRAY);
g.fillRect(222, y - 50, 8, 10);
// g.fillRect(372, y - 50, 8, 10);
g.drawLine(x1, y, x2, y);
// g.drawLine(x3, y, x4, y);
g.setColor(Color.BLACK);
g.drawString("Etage " + floor, 30, y - 45);
}
public int getFloor()
{
return this.floor;
}
}
*/
import javax.swing.*;
import java.awt.Color;
import java.awt.Graphics;
......@@ -98,16 +36,15 @@ public class Floor
g.setColor(Color.LIGHT_GRAY);
g.fillRect(222, y - 50, 8, 10);
//y-50
g.fillRect(222, y, 8, 10);
// g.fillRect(372, y - 50, 8, 10);
g.drawLine(x1, y, x2, y);
// g.drawLine(x3, y, x4, y);
g.setColor(Color.BLACK);
g.drawString("Etage " + floor, 30, y - 45);
g.drawString("Etage " + floor, 30, y-2);
}
......
......@@ -6,6 +6,9 @@ import javax.swing.JPanel;
public class Main
{
private static final int PANEL_WIDTH = 1000;
private static final int PANEL_HEIGHT = 900;
private JFrame frame;
private JPanel panel1;
private JPanel buttonsPanel;
......@@ -18,10 +21,11 @@ public class Main
public Main()
{
building = new Building(5);
building.setBounds(0, 0, 260, 500);
//h = 500
building = new Building(10);
building.setBounds(0, 0, 260, getPanelHeight());
btnStart = new JButton("Start");
/* btnStart = new JButton("Start");
btnStart.setBounds(290, 512, 80, 25);
btnStart.setFocusPainted(false);
btnStart.addActionListener((e) -> {
......@@ -36,7 +40,7 @@ public class Main
// building.stop();
System.out.println("pressed stop");
});
*/
//test
// Tạo panel con 2 và đặt vị trí của nó
buttonsPanel = new JPanel(new GridLayout(2,1,10,10));
......@@ -106,7 +110,7 @@ public class Main
panel1 = new JPanel(null);
//w=750
panel1.setPreferredSize(new Dimension(1000, 550));
panel1.setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
panel1.add(building);
// panel1.add(btnStart);
// panel1.add(btnStop);
......@@ -121,9 +125,17 @@ public class Main
frame.pack();
frame.setVisible(true);
}
public static int getPanelWidth() {
return PANEL_WIDTH;
}
public static int getPanelHeight() {
return PANEL_HEIGHT;
}
public static void main(String[] args)
{
Main main = new Main();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment