Add Dialog Image a Dialog Bar classes

This commit is contained in:
iryupnik 2020-03-12 18:47:52 +01:00
parent 1c292ce0fd
commit 8641d78c7e
5 changed files with 75 additions and 15 deletions

View File

@ -6,17 +6,27 @@ import java.awt.event.ActionListener;
public class Dialog {
private String text;
private int textLength;
private ImageDialog imageDialog;
private Timer timer;
private JPanel dialogBar;
private DialogBar dialogBar;
private int charNumber;
Dialog(String text, JPanel dialogBar) {
Dialog(String text, DialogBar dialogBar) {
this.text = text;
textLength = text.length() + 1;
this.dialogBar = dialogBar;
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) {
Font f1 = new Font("Times New Roman", Font.PLAIN, 20);
@ -26,7 +36,15 @@ public class Dialog {
text.setVisible(true);
text.setText(string);
Dimension size = text.getPreferredSize();
text.setBounds(20, 20, size.width, size.height);
if (imageDialog != null) {
text.setBounds(120, 20, size.width, size.height);
dialogBar.setImageDialog(imageDialog);
} else {
text.setBounds(20, 20, size.width, size.height);
dialogBar.unsetImageDialog();
}
return text;
}

View 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);
}
}
}

View 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();
}
}
}

View File

@ -21,7 +21,7 @@ public class WindowOfFreeMove extends JFrame {
static final int KEY_EVENT = 69;
private Canvas canvas;
private static JPanel dialogBar;
private DialogBar dialogBar;
private JLayeredPane lp;
private Map map;
private Timer timer;
@ -35,18 +35,10 @@ public class WindowOfFreeMove extends JFrame {
canvas.repaint();
}
public static JPanel getDialogBar() {
return dialogBar;
}
public static void setCanPersonMove(boolean canPersonMove) {
WindowOfFreeMove.canPersonMove = canPersonMove;
}
public static void setDialogBar(JPanel dialogBar) {
WindowOfFreeMove.dialogBar = dialogBar;
}
public void setMap(Map map) {
this.map = map;
}
@ -67,7 +59,7 @@ public class WindowOfFreeMove extends JFrame {
CELL_SIZE * CANVAS_HEIGHT));
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.setBackground(Color.BLACK);
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(4, 3, 8, 1, m4, this));
m1.addInteractionEvent(new InteractionCell(3, 5, new Dialog("Prvni zprava", dialogBar)));
m1.addInteractionEvent(new InteractionCell(5, 5, "druhá zpráva"));
m1.addInteractionEvent(new InteractionCell(3, 5, new Dialog("First line", dialogBar)));
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(1, 3, 8, 1, m1, this));
@ -226,6 +218,7 @@ public class WindowOfFreeMove extends JFrame {
}
}
protected static void sleep(long tm) {
try {
Thread.sleep(tm);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB