Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
elevator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NGUYEN Dang dinh
elevator
Commits
9caeae01
Commit
9caeae01
authored
Oct 1, 2023
by
NGUYEN Duc duong
Browse files
Options
Downloads
Patches
Plain Diff
fix Main
parent
54e6152c
No related branches found
No related tags found
No related merge requests found
Pipeline
#18819
passed
Oct 1, 2023
Stage: build
Stage: run
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/elevator/GUI/Main.java
+52
-26
52 additions, 26 deletions
src/main/java/elevator/GUI/Main.java
with
52 additions
and
26 deletions
src/main/java/elevator/GUI/Main.java
+
52
−
26
View file @
9caeae01
...
@@ -10,15 +10,12 @@ public class Main
...
@@ -10,15 +10,12 @@ public class Main
private
static
final
int
PANEL_HEIGHT
=
900
;
private
static
final
int
PANEL_HEIGHT
=
900
;
private
JFrame
frame
;
private
JFrame
frame
;
private
JPanel
panel1
;
private
JPanel
panel1
=
new
JPanel
(
null
)
;
private
JPanel
buttonsPanel
;
private
JPanel
buttonsPanel
;
private
JButton
btnStart
;
//
private JButton btnStart;
private
JButton
btnStop
;
//
private JButton btnStop;
private
Building
building
;
private
Building
building
;
private
JButton
[]
floorButtons
;
private
JButton
[]
floorButtons
;
private
JButton
[]
UandDBouton
;
private
JButton
[]
moveButtons
;
private
JPanel
moveButtonPanel
;
private
JPanel
[]
panelList
;
private
JPanel
[]
panelList
;
public
Main
()
public
Main
()
...
@@ -49,10 +46,10 @@ public class Main
...
@@ -49,10 +46,10 @@ public class Main
//buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
//buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
JPanel
numFloor
=
new
JPanel
();
JPanel
numFloor
=
new
JPanel
();
// numFloor.setLayout(new FlowLayout(10, 5));
// numFloor.setLayout(new FlowLayout(10, 5));
if
(
b
uilding
.
getNbFloor
()%
2
==
0
){
if
(
B
uilding
.
getNbFloor
()%
2
==
0
){
numFloor
=
new
JPanel
(
new
GridLayout
((
b
uilding
.
getNbFloor
()/
2
),
2
,
2
,
2
));
numFloor
=
new
JPanel
(
new
GridLayout
((
B
uilding
.
getNbFloor
()/
2
),
2
,
2
,
2
));
}
else
{
}
else
{
numFloor
=
new
JPanel
(
new
GridLayout
((
b
uilding
.
getNbFloor
()/
2
)
+
1
,
2
,
2
,
2
));
numFloor
=
new
JPanel
(
new
GridLayout
((
B
uilding
.
getNbFloor
()/
2
)
+
1
,
2
,
2
,
2
));
}
}
//numFloor.setBackground(new java.awt.Color(219, 217, 208));
//numFloor.setBackground(new java.awt.Color(219, 217, 208));
...
@@ -64,8 +61,8 @@ public class Main
...
@@ -64,8 +61,8 @@ public class Main
//x=450
//x=450
//x=260
//x=260
buttonsPanel
.
setBounds
(
500
,
100
,
200
,
250
);
// Đặt vị trí và kích thước của panel2
buttonsPanel
.
setBounds
(
500
,
100
,
200
,
250
);
// Đặt vị trí và kích thước của panel2
floorButtons
=
new
JButton
[
b
uilding
.
getNbFloor
()];
floorButtons
=
new
JButton
[
B
uilding
.
getNbFloor
()];
for
(
int
i
=
0
;
i
<
b
uilding
.
getNbFloor
();
i
++)
{
for
(
int
i
=
0
;
i
<
B
uilding
.
getNbFloor
();
i
++)
{
floorButtons
[
i
]
=
new
JButton
(
String
.
valueOf
(
i
));
floorButtons
[
i
]
=
new
JButton
(
String
.
valueOf
(
i
));
floorButtons
[
i
].
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
255
));
floorButtons
[
i
].
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
255
));
// floorButtons[i].setBounds();
// floorButtons[i].setBounds();
...
@@ -84,22 +81,49 @@ public class Main
...
@@ -84,22 +81,49 @@ public class Main
buttonsPanel
.
add
(
emergencyPanel
);
buttonsPanel
.
add
(
emergencyPanel
);
//button up and down
//button up and down
moveButtonPanel
=
new
JPanel
(
new
GridLayout
(
1
,
2
));
//moveButtonPanel = new JPanel(new GridLayout(1,2));
moveButtons
=
new
JButton
[
2
];
// moveButtons = new JButton[2];
panelList
=
new
JPanel
[
building
.
getNbFloor
()];
panelList
=
new
JPanel
[
Building
.
getNbFloor
()];
for
(
int
k
=
0
;
k
<=
Building
.
getNbFloor
();
k
++)
{
if
(
k
<
panelList
.
length
)
{
// Kiểm tra xem k có nằm trong giới hạn của mảng panelList không
panelList
[
k
]
=
new
JPanel
();
panelList
[
k
].
setLayout
(
new
GridLayout
(
1
,
2
,
5
,
5
));
JButton
upButton
=
new
JButton
(
"UP"
);
JButton
downButton
=
new
JButton
(
"DOWN"
);
if
(
k
==
0
)
{
panelList
[
k
].
add
(
upButton
);
panel1
.
add
(
panelList
[
k
]);
}
else
if
(
k
==
Building
.
getNbFloor
()
-
1
){
panelList
[
k
].
add
(
downButton
);
panel1
.
add
(
panelList
[
k
]);
}
panelList
[
k
].
add
(
upButton
);
panelList
[
k
].
add
(
downButton
);
panel1
.
add
(
panelList
[
k
]);
panelList
[
k
].
setBounds
(
262
,
(
Building
.
heightFloor
()
*
(
Building
.
getNbFloor
()
-
k
))
+
Building
.
heightFloor
()
/
2
,
150
,
Building
.
heightFloor
()
/
4
);
}
}
/*
for (int k = 0; k < building.getNbFloor(); k++){
for (int k = 0; k < building.getNbFloor(); k++){
panelList[k] = new JPanel();
panelList[k] = new JPanel();
//moveButtonPanel =new JPanel();
//moveButtonPanel =new JPanel();
panelList[k].setLayout(new GridLayout(1,2,5,5));
JButton upButton = new JButton("UP");
JButton upButton = new JButton("UP");
JButton downButton = new JButton("DOWN");
JButton downButton = new JButton("DOWN");
panelList[k].add(upButton);
moveButtons
[
0
]
=
upButton
;
panelList[k].add(downButton);
moveButtons
[
1
]
=
downButton
;
panelList[k].setBounds(262,(Building.heightFloor() * (building.getNbFloor() - k))+Building.heightFloor()/2, 150,Building.heightFloor()/4);
moveButtonPanel
.
add
(
moveButtons
[
0
]);
panel1.add(panelList[k]);
moveButtonPanel
.
add
(
moveButtons
[
1
]);
if (k==0){
panelList
[
k
].
add
(
moveButtonPanel
);
panelList[k].remove(downButton);
panel1.add(panelList[k]);
}
//moveButtonPanel.setBounds(262,(Building.heightFloor() * (2 - i))/4, 150,Building.heightFloor()/4 );
//moveButtonPanel.setBounds(262,(Building.heightFloor() * (2 - i))/4, 150,Building.heightFloor()/4 );
...
@@ -107,6 +131,8 @@ public class Main
...
@@ -107,6 +131,8 @@ public class Main
}
}
*/
/*
/*
moveButtonPanel = new JPanel();
moveButtonPanel = new JPanel();
moveButtonPanel.setBounds(260, 0,40,550);
moveButtonPanel.setBounds(260, 0,40,550);
...
@@ -133,17 +159,17 @@ public class Main
...
@@ -133,17 +159,17 @@ public class Main
panel1
=
new
JPanel
(
null
);
//
panel1 = new JPanel(null);
//w=750
//w=750
panel1
.
setPreferredSize
(
new
Dimension
(
PANEL_WIDTH
,
PANEL_HEIGHT
));
panel1
.
setPreferredSize
(
new
Dimension
(
PANEL_WIDTH
,
PANEL_HEIGHT
));
panel1
.
add
(
building
);
panel1
.
add
(
building
);
// panel1.add(btnStart);
// panel1.add(btnStart);
// panel1.add(btnStop);
// panel1.add(btnStop);
panel1
.
add
(
buttonsPanel
);
panel1
.
add
(
buttonsPanel
);
for
(
int
i
=
0
;
i
<
panelList
.
length
;
i
++){
/*
for (int i =0; i < panelList.length; i++){
panelList[i].setBounds(262,(Building.heightFloor() * (2 - i))/4, 150,Building.heightFloor()/4 );
panelList[i].setBounds(262,(Building.heightFloor() * (2 - i))/4, 150,Building.heightFloor()/4 );
panel1.add(panelList[i]);
panel1.add(panelList[i]);
}
}
*/
frame
=
new
JFrame
(
"Elevator Simulator"
);
frame
=
new
JFrame
(
"Elevator Simulator"
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment