java $s_java中%1$s什么意思啊?

importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassExampleextendsJFrame{staticExamplefrm=newExample();staticJTextFieldtxf=newJTextField();staticTextAr...

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Example extends JFrame {

static Example frm=new Example();

static JTextField txf=new JTextField();

static TextArea txa=new TextArea("",8,14,TextArea.SCROLLBARS_VERTICAL_ONLY);

static JTextArea txa1=new JTextArea();

public static void main(String[] args) {

Button btn=new Button("抽取");

Button btn1=new Button("退出");

frm.setTitle(" ");

frm.setSize(600,400);

frm.setLayout(null);

frm.setBackground(Color.gray);

frm.setResizable(false);

btn.setBounds(500,250,50,30);

btn1.setBounds(500,320,50,30);

txf.setBounds(20,50,200,30);

txa.setBounds(20,100,200,250);

txa1.setBounds(240,50,200,300);

txa1.setEditable(false);

txa.setEditable(false);

txa.setBackground(Color.white);

txf.addKeyListener(new Ky());

btn.addActionListener(new Act());

frm.add(btn);

frm.add(btn1);

frm.add(txf);

frm.add(txa);

frm.add(txa1);

frm.setVisible(true);

}

static class Ky implements KeyListener{

public void keyPressed(KeyEvent a){

if(a.getKeyChar()!='\n')

return;

String name=txf.getText();

if(name.isEmpty())

return;

txa.append(name+"\n");

txa.selectAll();

}

public void keyReleased(KeyEvent e) {

}

public void keyTyped(KeyEvent e) {

}

}

static class Act implements ActionListener{

public void actionPerformed(ActionEvent a){

String perstring=txa.getText();

String[] personnelArray=perstring.split("\n");

int index=(int)(Math.random()*personnelArray.length);

String formatArg="本次抽取观众人员:\n\t%1$s\n成为本次观众抽奖的大奖得主。"

+"\n\n我们将为%1$s颁发:\n\t过期的酸牛奶二十箱。";

String info=String.format(formatArg,personnelArray[index]);

txa1.setText(info);

}

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值