欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    Java知识重点梳理.docx

    • 资源ID:1219261       资源大小:54.80KB        全文页数:32页
    • 资源格式: DOCX        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Java知识重点梳理.docx

    1、Newnew是在堆中为对象men申请了一块空间。其中new实际是在调用父类的构造方法。注释 单行:/多行:/* */ /* */变量与常量一般常量(成员常量) final int x类常量 static int x修饰符关键字final(最终的)修饰的变量表示常量,赋值后无法改变修饰父类中Private成员方法,默认是final类型,表示不能被子类覆盖。Static (全局、静态)被static修饰的成员变量和成员方法独立于该类的任何对象。也就是说,它不依赖类特定的实例,被类的所有实例共享。static对象可以在它的任何对象创建之前访问,无需引用任何对象。private是访问权限限定,stat

    2、ic表示不要实例化就可以使用三大特性:继承,多态,封装。继承:继承是为了重用父类代码,同时为实现多态性作准备。能够大大缩短开发周期,降低开发费用。封装:类使得数据和对数据的操作集成在一起,从而对使用该类的其他人来说,可以不管它的实现方法,而只管用它的功能,从而实现所谓的信息隐藏。多态:方法的重写、重载与动态连接构成多态性。因为单继承的限制,(猫 extends 动物),造成功能上的限制,所以引入多态。重载、重写重载:多个同名函数同时存在,具有不同的参数个数/类型。(型构不同)重写(覆盖):重写方法只能存在于具有继承关系中,重写方法只能重写父类非私有的方法。当子类继承自父类的相同方法,输入数据一

    3、样,但要做出有别于父类的响应时,你就要覆盖父类方法,即在子类中重写该方法相同型构,不同实现。最终目的:设计一个结构清晰而简洁的类接口与抽象类abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制。对比:抽象类表示该类中可能已经有一些方法的具体定义,但是接口就仅仅只能定义各个方法的界面(方法名,参数列表,返回类型),并不关心具体细节。从某种意义上说,interface是一种特殊形式的abstract class。类是现实中实际存在的事物。抽象类:实际不存在的抽象概念,即一些性质的集合,比如Object、形状、家、生物、神仙等等抽象类里面可以有非抽象方法但

    4、接口里只能有抽象方法 声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。接口(interface)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。Java Swing一个用户登录框实例SwingLoginExample.java 文件代码如下:import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import j

    5、avax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField; public class SwingLoginExample public static void main(String args) / 创建 JFrame 实例 JFrame frame = new JFrame(Login Example); / Setting the width and height of frame frame.setSize(350, 200); frame.setDefaultCloseOperat

    6、ion(JFrame.EXIT_ON_CLOSE); /* 创建面板,这个类似于 HTML 的 div 标签 * 我们可以创建多个面板并在 JFrame 中指定位置 * 面板中我们可以添加文本字段,按钮及其他组件。 */ JPanel panel = new JPanel(); / 添加面板 frame.add(panel); /* * 调用用户定义的方法并添加组件到面板 */ placeComponents(panel); / 设置界面可见 frame.setVisible(true); private static void placeComponents(JPanel panel) /*

    7、 布局部分我们这边不多做介绍 * 这边设置布局为 null */ panel.setLayout(null); / 创建 JLabel JLabel userLabel = new JLabel(User:); /* 这个方法定义了组件的位置。 * setBounds(x, y, width, height) * x 和 y 指定左上角的新位置,由 width 和 height 指定新的大小。 */ userLabel.setBounds(10,20,80,25); panel.add(userLabel); /* * 创建文本域用于用户输入 */ JTextField userText =

    8、new JTextField(20); userText.setBounds(100,20,165,25); panel.add(userText); / 输入密码的文本域 JLabel passwordLabel = new JLabel(Password:); passwordLabel.setBounds(10,50,80,25); panel.add(passwordLabel); /* *这个类似用于输入的文本域 * 但是输入的信息会以点号代替,用于包含密码的安全性 */ JPasswordField passwordText = new JPasswordField(20); pa

    9、sswordText.setBounds(100,50,165,25); panel.add(passwordText); / 创建登录按钮 JButton loginButton = new JButton(login); loginButton.setBounds(10, 80, 80, 25); panel.add(loginButton); 执行以下命令输出结果:$ javac SwingLoginExample.java$ java SwingLoginExample概念解析:JFrame java的GUI程序的基本思路是以JFrame为基础,它是屏幕上window的对象,能够最大化

    10、、最小化、关闭。JPanel Java图形用户界面(GUI)工具包swing中的面板容器类,包含在javax.swing 包中,可以进行嵌套,功能是对窗体中具有相同逻辑功能的组件进行组合,是一种轻量级容器,可以加入到JFrame窗体中。JLabel JLabel 对象可以显示文本、图像或同时显示二者。可以通过设置垂直和水平对齐方式,指定标签显示区中标签内容在何处对齐。默认情况下,标签在其显示区内垂直居中对齐。默认情况下,只显示文本的标签是开始边对齐;而只显示图像的标签则水平居中对齐。JTextField一个轻量级组件,它允许编辑单行文本。JPasswordField 允许我们输入了一行字像输入

    11、框,但隐藏星号(*) 或点创建密码(密码)JButton JButton 类的实例。用于创建按钮类似实例中的 Login。事件监听* * Java事件监听处理自身类实现ActionListener接口,作为事件监听器 * * author codebrother */class EventListener1 extends JFrame implements ActionListener private JButton btBlue, btDialog; public EventListener1() setTitle(Java GUI 事件监听处理); setBounds(100, 100,

    12、 500, 350); setLayout(new FlowLayout(); btBlue = new JButton(蓝色); btDialog = new JButton(弹窗); / 将按钮添加事件监听器 btBlue.addActionListener(this); btDialog.addActionListener(this); add(btBlue); add(btDialog); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / *事件处理* Override public void act

    13、ionPerformed(ActionEvent e) if (e.getSource() = btBlue) Container c = getContentPane(); c.setBackground(Color.BLUE); else if (e.getSource() = btDialog) JDialog dialog = new JDialog(); dialog.setBounds(300, 200, 400, 300); dialog.setVisible(true); /* * Java事件监听处理内部类处理 * * author codebrother */class E

    14、ventListener3 extends JFrame private JButton btBlue, btDialog; / 构造方法 public EventListener3() setTitle(Java GUI 事件监听处理); setBounds(100, 100, 500, 350); setLayout(new FlowLayout(); btBlue = new JButton(蓝色); btDialog = new JButton(弹窗); / 添加事件监听器对象(面向对象思想) btBlue.addActionListener(new ColorEventListene

    15、r(); btDialog.addActionListener(new DialogEventListener(); add(btBlue); add(btDialog); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / 内部类ColorEventListener,实现ActionListener接口 class ColorEventListener implements ActionListener Override public void actionPerformed(ActionEvent e) C

    16、ontainer c = getContentPane(); c.setBackground(Color.BLUE); / 内部类DialogEventListener,实现ActionListener接口 class DialogEventListener implements ActionListener Override public void actionPerformed(ActionEvent e) JDialog dialog = new JDialog(); dialog.setBounds(300, 200, 400, 300); dialog.setVisible(true

    17、); /* * Java事件监听处理匿名内部类处理 * * author codebrother */class EventListener2 extends JFrame private JButton btBlue, btDialog; public EventListener2() setTitle(Java GUI 事件监听处理); setBounds(100, 100, 500, 350); setLayout(new FlowLayout(); btBlue = new JButton(蓝色); btDialog = new JButton(弹窗); / 添加事件监听器(此处即为匿

    18、名类) btBlue.addActionListener(new ActionListener() / 事件处理 Override public void actionPerformed(ActionEvent e) Container c = getContentPane(); c.setBackground(Color.BLUE); ); / 并添加事件监听器 btDialog.addActionListener(new ActionListener() Override public void actionPerformed(ActionEvent e) JDialog dialog =

    19、 new JDialog(); dialog.setBounds(300, 200, 400, 300); dialog.setVisible(true); ); add(btBlue); add(btDialog); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /* * Java事件监听处理外部类处理 * * author codebrother */class EventListener4 extends JFrame private JButton btBlue, btDialog; public E

    20、ventListener4() setTitle(Java GUI 事件监听处理); setBounds(100, 100, 500, 350); setLayout(new FlowLayout(); btBlue = new JButton(蓝色); btDialog = new JButton(弹窗); / 将按钮添加事件监听器 btBlue.addActionListener(new ColorEventListener(this); btDialog.addActionListener(new DialogEventListener(); add(btBlue); add(btDia

    21、log); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / 外部类ColorEventListener,实现ActionListener接口class ColorEventListener implements ActionListener private EventListener4 el; ColorEventListener(EventListener4 el) this.el = el; Override public void actionPerformed(ActionEvent e) Cont

    22、ainer c = el.getContentPane(); c.setBackground(Color.BLUE); / 外部类DialogEventListener,实现ActionListener接口class DialogEventListener implements ActionListener Override public void actionPerformed(ActionEvent e) JDialog dialog = new JDialog(); dialog.setBounds(300, 200, 400, 300); dialog.setVisible(true)

    23、; public class ActionListenerTest public static void main(String args) new EventListener2(); 游戏实战:坦克大战设计思路必须提前理清:Blood.javapackage com.hkm.TankWar;import java.awt.*;/* * 血块类,我方坦克吃了可回血; * author Hekangmin * */public class Blood private int x,y,w,h;/血块的位置和宽度高度; private TankWarClient tc; private int st

    24、ep=0;/纪录血块移动的步数; private boolean live=true; public boolean isLive() return live; public void setLive(boolean live) this.live = live; /* * 纪录血块的位置; */ private int pos=400,300,400,320,420,320,440,300,440,330,480,400,520,400,540,400; public Blood() x=pos00; y=pos01; w=h=18; public void draw(Graphics g)

    25、 if(!live) return; Color c=g.getColor(); g.setColor(Color.CYAN); g.fillOval(x, y, w, h); g.setColor(c); move(); /* * 移动血块 */ public void move() step+; if(step=pos.length) step=0; else x=posstep0; y=posstep1; public Rectangle getRect() return new Rectangle(x,y,w,h); Explode.javapackage com.hkm.TankWa

    26、r;import java.awt.*;/* * 爆炸类 * author Hekangmin * */public class Explode private int x,y;/爆炸发生的位置 private boolean Live=true; int dia=4,8,12,16,32,40,20,14,4;/用园模拟,代表圆的直径; int step=0;/区别移到第几个直径 private TankWarClient tc;/持有引用 public Explode(int x,int y,TankWarClient tc) this.x=x; this.y=y; this.tc=tc; public void draw(Graphics g) if(!Live)


    注意事项

    本文(Java知识重点梳理.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开