aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ui/OpponentConfirmation.java
blob: d0c2a957b51b5582c25a1f5efc4dc031668d2236 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package ui;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import models.ComboBoxUser;
import models.User;

import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

public class OpponentConfirmation extends JPanel {
	public JLabel lblNewLabel;
	public JButton btnAccept;
	public JButton btnRefuse;
	public long opponentId;
	
	public OpponentConfirmation() {
		setLayout(null);
		
		lblNewLabel = new JLabel("New label");
		lblNewLabel.setBounds(95, 66, 208, 98);
		add(lblNewLabel);
		
		btnAccept = new JButton("Accept");
		btnAccept.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String msg="ACCEPTOPPONENT:"+opponentId;
				ByteBuffer bb=ByteBuffer.wrap(msg.getBytes());
				MainFrame topFrame=(MainFrame) SwingUtilities.getAncestorOfClass(MainFrame.class, OpponentConfirmation.this);
				try {
					SocketChannel client=topFrame.getClient();
					client.write(bb);
					SwingUtilities.updateComponentTreeUI(topFrame);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				
				
			}
		});
		btnAccept.setBounds(92, 194, 89, 23);
		add(btnAccept);
		
		btnRefuse = new JButton("Refuse");
		btnRefuse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String msg="REFUSEOPPONENT:"+opponentId;
				ByteBuffer bb=ByteBuffer.wrap(msg.getBytes());
				MainFrame topFrame=(MainFrame) SwingUtilities.getAncestorOfClass(MainFrame.class, OpponentConfirmation.this);
				try {
					SocketChannel client=topFrame.getClient();
					client.write(bb);
					SwingUtilities.updateComponentTreeUI(topFrame);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		btnRefuse.setBounds(214, 194, 89, 23);
		add(btnRefuse);

	}
	public long getOpponentId() {
		return opponentId;
	}
	public void setOpponentId(long opponentId) {
		this.opponentId = opponentId;
	}
	public JLabel getLblNewLabel() {
		return lblNewLabel;
	}
	public void setLblNewLabel(JLabel lblNewLabel) {
		this.lblNewLabel = lblNewLabel;
	}
	public JButton getBtnAccept() {
		return btnAccept;
	}
	public void setBtnAccept(JButton btnAccept) {
		this.btnAccept = btnAccept;
	}
	public JButton getBtnRefuse() {
		return btnRefuse;
	}
	public void setBtnRefuse(JButton btnRefuse) {
		this.btnRefuse = btnRefuse;
	}
}