java设计游戏选项界面_基于java平台设计--游戏界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

public class Third

{

public Third th;

public JFrame jf3;

public DrawQiPan QiPan;

public static String name2;

public static String headicon2;

public static JTextArea talk = new JTextArea();

public static Stack stack = new Stack();

private JButton jb1 = new JButton("退出");

private JButton jb2 = new JButton("开始");

private JButton jb3 = new JButton("求和");

private JButton jb4 = new JButton("悔棋");

private JButton jb5 = new JButton("认输");

private JButton jb6 = new JButton("发送");

private JTextField Text = new JTextField();

private JTextField name;

private JLabel headicon;

public Third(Third th,JFrame jf3,DrawQiPan QiPan,JTextField name,JLabel headicon)

{

try

{

this.th = th;

this.jf3 = jf3;

this.QiPan = QiPan;

this.name = name;

this.headicon = headicon;

}

catch(Exception e)

{

e.printStackTrace();

}

}

public JSplitPane createPane()

{

JTabbedPane jtp1 = new JTabbedPane();

JTabbedPane jtp2 = new JTabbedPane();

JTabbedPane jtp3 = new JTabbedPane();

JTabbedPane jtp4 = new JTabbedPane();

JPanel jp1 = new JPanel();

JPanel jp12 = new JPanel();

JPanel jp2 = new JPanel();

JPanel jp22 = new JPanel();

JPanel jp4 = new JPanel();

JPanel jp42 = new JPanel();

JPanel jp51 = new JPanel();

JLabel jl11 = new JLabel(new ImageIcon("./res/img/5.gif"));

JLabel jl121 = new JLabel(new ImageIcon(headicon2),JLabel.CENTER);

JLabel jl122 = new JLabel(name2);

JLabel jl13 = new JLabel("剩余时间:");

JLabel jl21 = new JLabel(new ImageIcon("./res/img/21.gif"));

JLabel jl222 = new JLabel(name.getText());

JLabel jl23 = new JLabel("剩余时间:");

JLabel jl511 = new JLabel("<<>>");

J_Action a = new J_Action();

JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

JSplitPane leftSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

JSplitPane rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

JSplitPane left_leftSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

jp12.add(jl121);

jp12.add(jl122);

jp1.setLayout(null);

jp1.add(jl11);

jp1.add(jp12);

jp1.add(jl13);

jl11.setBounds(17, 17, 108, 113);

jp12.setBounds(40, 170, 70, 40);

jl13.setBounds(0, 240, 158, 40);

jp1.setBackground(new Color(255,255,255));

jtp1.addTab("对手信息", null, jp1, "对手信息");

jp22.add(headicon);

jp22.add(jl222);

jp2.setLayout(null);

jp2.add(jl21); // 左边模块

jp2.add(jp22);

jp2.add(jl23);

jl21.setBounds(17, 17, 108, 113);

jp22.setBounds(40, 170, 70, 40);

jl23.setBounds(0, 240, 158, 40);

jp2.setBackground(new Color(255,255,255));

jtp2.addTab("玩家信息", new ImageIcon("./res/img/star.gif"), jp2, "玩家信息");

left_leftSplitPane.setDividerLocation(310);

left_leftSplitPane.setDividerSize(5);

left_leftSplitPane.setTopComponent(jtp1); //左边的面板分配方法

left_leftSplitPane.setBottomComponent(jtp2);

leftSplitPane.setDividerLocation(150);

leftSplitPane.setDividerSize(5);

leftSplitPane.setLeftComponent(left_leftSplitPane); /

String players[] = {name2, name.getText()}; /

JList jl3 = new JList(players);

JScrollPane jsp3=new JScrollPane(jl3);

jtp3.addTab("用户列表", null, jsp3, "用户列表");

JScrollPane jsp41 = new JScrollPane(talk);

jp42.setLayout(new FlowLayout());

Text = new JTextField(7);

Text.setActionCommand("发送");

Text.addActionListener(a);

jb6.setActionCommand("发送");

jb6.addActionListener(a); // 右边模块

jp42.add(Text);

jp42.add(jb6);

jp4.setLayout(new BorderLayout());

jp4.add(jsp41, "Center");

jp4.add(jp42, "South");

jtp4.addTab("聊天", null, jp4, "聊天");

rightSplitPane.setTopComponent(jtp3);

rightSplitPane.setBottomComponent(jtp4); //右边面板分配方法

rightSplitPane.setDividerLocation(300);

rightSplitPane.setDividerSize(5); //

jp51.setLayout(null); /

jb1.setActionCommand("退出");

jp51.add(jl511);

jp51.add(jb1);

jl511.setBounds(5, 1, 150, 30);

jb1.setBounds(390, 7, 60, 30);

JPanel jp522 = new JPanel();

jp522.setLayout(new FlowLayout()); //流式布局

jb2.setActionCommand("开始");

jb3.setActionCommand("求和");

jb4.setActionCommand("悔棋");

jb5.setActionCommand("认输");

jp522.add(jb2);

jp522.add(jb3);

jp522.add(jb4);

jp522.add(jb5);

jb1.addActionListener(a);

jb2.addActionListener(a); // 中间模块,设置监听器

jb3.addActionListener(a);

jb4.addActionListener(a);

jb5.addActionListener(a);

JPanel jp52 = new JPanel();

jp52.setLayout(new BorderLayout());

JPanel jp521 = new JPanel();

jp521.setPreferredSize(new Dimension(470, 550));

jp521.setLayout(new BorderLayout());

jp521.add(QiPan);

jp52.add(jp521, "Center");

jp52.add(jp522, "South");

JPanel jp5 = new JPanel();

jp5.setLayout(new BorderLayout());

jp5.add(jp51, "Center");

jp5.add(jp52, "South");

leftSplitPane.setRightComponent(jp5);

mainSplitPane.setDividerSize(5);

mainSplitPane.setRightComponent(rightSplitPane);

mainSplitPane.setLeftComponent(leftSplitPane);

mainSplitPane.setDividerLocation(610);

return mainSplitPane;

}

class J_Action implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

JButton b =(JButton)e.getSource();

if(b == jb1)

{

jf3.setVisible(false); //退出按钮

}

else if (b == jb2) //开始按钮

{

QiPan.HaveStart = true;

try

{

JOptionPane.showMessageDialog(null,"游戏开始", "开始游戏", JOptionPane.INFORMATION_MESSAGE);

Second.dos.writeUTF("Start");

Second.dos.writeUTF(name2);

}

catch(Exception ee)

{

ee.printStackTrace();

}

QiPan.repaint();

}

else if(b == jb6) //聊天发送

{

String s1 = Text.getText();

try{

Second.dos.writeUTF("Chat");

Second.dos.writeUTF(name2);

Second.dos.writeUTF(s1);

}catch(Exception ee)

{

ee.printStackTrace();

}

talk.append(s1 + "\n");

Text.setText(null);

}

}

}

}

?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值