企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ package kehuduan.view; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class List extends JFrame implements ActionListener,MouseListener{ JPanel jphy1,jphy2,jphy3;//面板1,2,3 JButton jphy_jb1,jphy_jb2,jphy_jb3;//按钮1,2,3 JScrollPane jsp1;//滚动条1 JLabel []jb1s;//数组标签 JPanel jpmsr1,jpmsr2,jpmsr3;//面板1,2,3 JButton jpmsr_jb1,jpmsr_jb2,jpmsr_jb3;//按钮1,2,3 JLabel []jb1s2;//数组标签 JScrollPane jsp2;//滚动条2 CardLayout cl; String owner; public static void main(String[] args) { List t=new List("3"); } public List(String ownerId){ /********111start**********/ jphy_jb1=new JButton("我的好友"); jphy_jb2=new JButton("陌生人"); jphy_jb2.addActionListener(this); jphy_jb3=new JButton("黑名单"); jphy1=new JPanel(new BorderLayout());//面板1-边界布局 //面板2-网格布局//50行1列水平间距4垂直间距4 jphy2=new JPanel(new GridLayout(50,1,4,4)); jb1s =new JLabel[50];//长度为50的数组标签 //给数组标签添加值 for(int i=0;i<jb1s.length;i++) { jb1s[i]=new JLabel(i+1+"",new ImageIcon("image/mm.jpg"),JLabel.LEFT); jb1s[i].setEnabled(false);//不可点击 if(jb1s[i].getText().equals(ownerId)) { jb1s[i].setEnabled(true);//可点击 } jb1s[i].addMouseListener(this); jphy2.add(jb1s[i]); //将标签添加到面板2 } jphy3=new JPanel(new GridLayout(2,1));//面板3-网格布局2行1列 jphy3.add(jphy_jb2);//陌生人添加到面板3 jphy3.add(jphy_jb3);//黑名单添加到面板3 jsp1=new JScrollPane(jphy2);//将面板2放入滚动条1 jphy1.add(jphy_jb1,"North");//上-按钮1 jphy1.add(jsp1,"Center");//中-滚动条 jphy1.add(jphy3,"South");//下-面板3 /********111end**********/ /********222start**********/ jpmsr_jb1=new JButton("我的好友"); jpmsr_jb1.addActionListener(this); jpmsr_jb2=new JButton("陌生人"); jpmsr_jb3=new JButton("黑名单"); jpmsr1=new JPanel(new BorderLayout());//面板1-边界布局 //面板2-网格布局//20行1列水平间距4垂直间距4 jpmsr2=new JPanel(new GridLayout(20,1,4,4)); jb1s2=new JLabel[20];//长度为20的数组标签 //给数组标签添加值 for(int i=0;i<jb1s2.length;i++) { jb1s2[i]=new JLabel(i+1+"",new ImageIcon("image/mm.jpg"),JLabel.LEFT); jpmsr2.add(jb1s2[i]);//将标签添加到面板2 } jpmsr3=new JPanel(new GridLayout(2,1));//面板3-网格布局2行1列 jpmsr3.add(jpmsr_jb1);//我的好友添加到面板3 jpmsr3.add(jpmsr_jb2);//陌生人添加到面板3 jsp2=new JScrollPane(jpmsr2);//将面板2放入滚动条2 jpmsr1.add(jpmsr3,"North");//上-面板3 jpmsr1.add(jsp2,"Center");//中-滚动条 jpmsr1.add(jpmsr_jb3,"South");//下-按钮3 /********222end**********/ cl=new CardLayout(); this.setLayout(cl); this.add(jphy1, "1"); this.add(jpmsr1,"2"); this.owner=ownerId; this.setTitle(ownerId); this.setSize(140, 400); this.setLocation(318,186); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==jphy_jb2) { cl.show(this.getContentPane(), "2"); } else if(e.getSource()==jpmsr_jb1) { cl.show(this.getContentPane(), "1"); } } @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub if(e.getClickCount()==2)//双击 { String friendNo=((JLabel)e.getSource()).getText(); Chat lt=new Chat(this.owner,friendNo); //Glliaotian.addLiaotian(this.owner+" "+friendNo,lt); } } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } } ~~~ ![](https://box.kancloud.cn/e3b8ee2cd38cebcb187db6475978eccf_138x397.png)