Java 学习笔记

Author:MWhite
Update time:17.11.12


视图

JFrame

    this.setSize(new Dimension(300, 300));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setLocation(500, 400);

    // 添加成员组件
    this.bv = new BoardView(this.game.getBoard());
    this.bv.addMouseListener(new GameController(this));
    this.setContentPane(this.子组件名);
    this.pack();//是调整外部容器大小的方法,自动调整成刚好装下内部组件。
    this.setVisible(true);

字符串

  1. 截取字符串
int a=line.indexOf(',');
String name = line.substring(0,a);
  1. 替换
String newstr = line.replace(",", " ");
trim();

List

List<String> list = new ArrayList<String>();
遍历
方法一:
超级for循环遍历
for(String attribute : list) {
System.out.println(attribute);
}
方法二:
对于ArrayList来说速度比较快, 用for循环, 以size为条件遍历:
for(int i = 0 ; i < list.size() ; i++) {
System.out.println(list.get(i));
}
方法三:
集合类的通用遍历方式, 从很早的版本就有, 用迭代器迭代
Iterator it = list.iterator();
while(it.hasNext()) {
System.ou.println(it.next);
}

窗口

System.exit(0);
dispose()

添加图片

JLabel helloLabel = new JLabel("");
helloLabel.setIcon(new ImageIcon("image\\background.jpg"));
helloLabel.setBackground(Color.BLACK);
helloLabel.setBounds(0, 0, 105, 50);        
this.add(helloLabel);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 每日要点 容器 容器(集合框架Container) - 承载其他对象的对象 Collection List Arr...
    迷茫o阅读 1,196评论 0 0
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 32,143评论 18 399
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 5,947评论 0 2
  • 第三十六章,继续挣扎 她们已经离开了北京,开始了新的生活,换了号码,断了联系,祝他们幸福。 我们公司还有一部分的业...
    郭磊guolei阅读 1,677评论 0 0
  • 文|安小羽 我见识过很多人,自信的,勇敢的,坚强的,什么都不怕的。但如果真的让我说有没有遇到过什么都不怕的人,我不...
    安羽心理阅读 12,942评论 0 2