2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JPanel;
|
2021-07-16 00:37:03 +02:00
|
|
|
import javax.swing.JMenuBar;
|
|
|
|
import javax.swing.JMenu;
|
2021-07-16 01:07:23 +02:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.Box;
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
import java.awt.Graphics;
|
2021-07-16 00:37:03 +02:00
|
|
|
import java.awt.Dimension;
|
2021-07-16 01:07:23 +02:00
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.GridLayout;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.ArrayList;
|
2021-07-16 00:37:03 +02:00
|
|
|
|
|
|
|
class
|
|
|
|
PostWindow extends JFrame {
|
|
|
|
|
|
|
|
private PostComponent
|
|
|
|
posts;
|
|
|
|
|
|
|
|
private RepliesComponent
|
|
|
|
replies;
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
PostWindow()
|
|
|
|
{
|
|
|
|
setLocationByPlatform(true);
|
|
|
|
|
|
|
|
posts = new PostComponent();
|
|
|
|
|
|
|
|
replies = new RepliesComponent();
|
|
|
|
|
|
|
|
JMenu postMenu = new JMenu("Post");
|
|
|
|
postMenu.add("Favourite");
|
|
|
|
postMenu.add("Reply");
|
|
|
|
postMenu.add("Show replies");
|
|
|
|
JMenuBar menuBar = new JMenuBar();
|
|
|
|
menuBar.add(postMenu);
|
|
|
|
setJMenuBar(menuBar);
|
|
|
|
|
|
|
|
setContentPane(posts);
|
|
|
|
setSize(360, 270);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-16 01:07:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
PostComponent extends JPanel {
|
|
|
|
|
|
|
|
private String
|
|
|
|
author, time, text;
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
setAuthor(String author)
|
|
|
|
{
|
|
|
|
assert author != null;
|
|
|
|
this.author = author;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setTime(String time)
|
|
|
|
{
|
|
|
|
assert time != null;
|
|
|
|
this.time = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void
|
|
|
|
setText(String text)
|
|
|
|
{
|
|
|
|
assert text != null;
|
|
|
|
this.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - -%- -
|
|
|
|
|
|
|
|
protected void
|
|
|
|
paintComponent(Graphics g)
|
|
|
|
{
|
|
|
|
int lineHeight = 24;
|
|
|
|
|
|
|
|
g.drawString(author, 0, lineHeight);
|
|
|
|
|
|
|
|
g.drawString(text, 0, 2 * lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
PostComponent()
|
|
|
|
{
|
|
|
|
author = "Author";
|
|
|
|
time = "Time";
|
|
|
|
text = "This is a soft post..";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class
|
|
|
|
RepliesComponent extends JPanel {
|
|
|
|
|
|
|
|
private List<String>
|
|
|
|
authors, texts;
|
|
|
|
|
|
|
|
private JButton
|
|
|
|
prevPage, nextPage;
|
|
|
|
|
|
|
|
private JLabel
|
|
|
|
pageLabel;
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
public void
|
|
|
|
setReplies(List<String> authors, List<String> texts)
|
|
|
|
{
|
|
|
|
this.authors.clear();
|
|
|
|
this.authors.addAll(authors);
|
|
|
|
this.texts.clear();
|
|
|
|
this.texts.addAll(texts);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---%-@-%---
|
|
|
|
|
|
|
|
RepliesComponent()
|
|
|
|
{
|
|
|
|
authors = new ArrayList<>();
|
|
|
|
texts = new ArrayList<>();
|
|
|
|
|
|
|
|
prevPage = new JButton("<");
|
|
|
|
nextPage = new JButton(">");
|
|
|
|
prevPage.setEnabled(false);
|
|
|
|
nextPage.setEnabled(false);
|
|
|
|
|
|
|
|
pageLabel = new JLabel("0 / 0");
|
|
|
|
|
|
|
|
Box bottom = Box.createHorizontalBox();
|
|
|
|
bottom.add(Box.createGlue());
|
|
|
|
bottom.add(prevPage);
|
|
|
|
bottom.add(pageLabel);
|
|
|
|
bottom.add(nextPage);
|
|
|
|
|
|
|
|
JPanel centre = new JPanel();
|
|
|
|
centre.setLayout(new GridLayout(0, 1, 0, 2));
|
|
|
|
for (int n = 8; n > 0; --n) {
|
|
|
|
String label = "Eggplant -%- A short reply..";
|
|
|
|
JButton reply = new JButton(label);
|
|
|
|
// We likely need a custom class..
|
|
|
|
centre.add(reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
setLayout(new BorderLayout(4, 4));
|
|
|
|
add(centre, BorderLayout.CENTER);
|
|
|
|
add(bottom, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|