Add Dialog Image a Dialog Bar classes
This commit is contained in:
parent
1c292ce0fd
commit
8641d78c7e
@ -6,17 +6,27 @@ import java.awt.event.ActionListener;
|
|||||||
public class Dialog {
|
public class Dialog {
|
||||||
private String text;
|
private String text;
|
||||||
private int textLength;
|
private int textLength;
|
||||||
|
private ImageDialog imageDialog;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private JPanel dialogBar;
|
private DialogBar dialogBar;
|
||||||
private int charNumber;
|
private int charNumber;
|
||||||
|
|
||||||
Dialog(String text, JPanel dialogBar) {
|
Dialog(String text, DialogBar dialogBar) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
textLength = text.length() + 1;
|
textLength = text.length() + 1;
|
||||||
this.dialogBar = dialogBar;
|
this.dialogBar = dialogBar;
|
||||||
charNumber = 0;
|
charNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dialog(String text, DialogBar dialogBar, ImageDialog imageDialog) {
|
||||||
|
this.text = text;
|
||||||
|
this.imageDialog = imageDialog;
|
||||||
|
textLength = text.length() + 1;
|
||||||
|
this.dialogBar = dialogBar;
|
||||||
|
charNumber = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private JLabel prepareDialogBar(String string) {
|
private JLabel prepareDialogBar(String string) {
|
||||||
Font f1 = new Font("Times New Roman", Font.PLAIN, 20);
|
Font f1 = new Font("Times New Roman", Font.PLAIN, 20);
|
||||||
|
|
||||||
@ -26,7 +36,15 @@ public class Dialog {
|
|||||||
text.setVisible(true);
|
text.setVisible(true);
|
||||||
text.setText(string);
|
text.setText(string);
|
||||||
Dimension size = text.getPreferredSize();
|
Dimension size = text.getPreferredSize();
|
||||||
|
|
||||||
|
if (imageDialog != null) {
|
||||||
|
text.setBounds(120, 20, size.width, size.height);
|
||||||
|
dialogBar.setImageDialog(imageDialog);
|
||||||
|
} else {
|
||||||
text.setBounds(20, 20, size.width, size.height);
|
text.setBounds(20, 20, size.width, size.height);
|
||||||
|
dialogBar.unsetImageDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/main/java/DialogBar.java
Normal file
22
src/main/java/DialogBar.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DialogBar extends JPanel {
|
||||||
|
private ImageDialog imageDialog;
|
||||||
|
|
||||||
|
public void setImageDialog(ImageDialog imageDialog) {
|
||||||
|
this.imageDialog = imageDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsetImageDialog(){
|
||||||
|
imageDialog = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
if (imageDialog != null){
|
||||||
|
g.drawImage(imageDialog.getImage(), 0, 0, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/main/java/ImageDialog.java
Normal file
27
src/main/java/ImageDialog.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ImageDialog {
|
||||||
|
private String name;
|
||||||
|
private Image image;
|
||||||
|
|
||||||
|
public Image getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageDialog(String name){
|
||||||
|
this.name = name;
|
||||||
|
parseImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseImage(){
|
||||||
|
try {
|
||||||
|
image = ImageIO.read(getClass().getResource(name));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
static final int KEY_EVENT = 69;
|
static final int KEY_EVENT = 69;
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private static JPanel dialogBar;
|
private DialogBar dialogBar;
|
||||||
private JLayeredPane lp;
|
private JLayeredPane lp;
|
||||||
private Map map;
|
private Map map;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
@ -35,18 +35,10 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JPanel getDialogBar() {
|
|
||||||
return dialogBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCanPersonMove(boolean canPersonMove) {
|
public static void setCanPersonMove(boolean canPersonMove) {
|
||||||
WindowOfFreeMove.canPersonMove = canPersonMove;
|
WindowOfFreeMove.canPersonMove = canPersonMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDialogBar(JPanel dialogBar) {
|
|
||||||
WindowOfFreeMove.dialogBar = dialogBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMap(Map map) {
|
public void setMap(Map map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
@ -67,7 +59,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
CELL_SIZE * CANVAS_HEIGHT));
|
CELL_SIZE * CANVAS_HEIGHT));
|
||||||
canvas.setBounds(0, 0, CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH);
|
canvas.setBounds(0, 0, CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH);
|
||||||
|
|
||||||
dialogBar = new JPanel();
|
dialogBar = new DialogBar();
|
||||||
dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
|
dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
|
||||||
dialogBar.setBackground(Color.BLACK);
|
dialogBar.setBackground(Color.BLACK);
|
||||||
dialogBar.setVisible(false);
|
dialogBar.setVisible(false);
|
||||||
@ -151,8 +143,8 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
|
|
||||||
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
|
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
|
||||||
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
|
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
|
||||||
m1.addInteractionEvent(new InteractionCell(3, 5, new Dialog("Prvni zprava", dialogBar)));
|
m1.addInteractionEvent(new InteractionCell(3, 5, new Dialog("First line", dialogBar)));
|
||||||
m1.addInteractionEvent(new InteractionCell(5, 5, "druhá zpráva"));
|
m1.addInteractionEvent(new InteractionCell(5, 5, new Dialog("Second line", dialogBar, new ImageDialog("BaetoriceFace.png"))));
|
||||||
|
|
||||||
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
|
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
|
||||||
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));
|
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));
|
||||||
@ -226,6 +218,7 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static void sleep(long tm) {
|
protected static void sleep(long tm) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(tm);
|
Thread.sleep(tm);
|
||||||
|
|||||||
BIN
src/main/resources/BaetoriceFace.png
Normal file
BIN
src/main/resources/BaetoriceFace.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
x
Reference in New Issue
Block a user