import java.awt.*;
import javax.swing.*;
import javax.swing.JFrame;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Desktop;
import java.awt.Cursor; public class LinkLabel extends JLabel implements MouseListener
{
protected String text;
protected boolean isSupported;
protected JFrame parent = null;
public LinkLabel(String text, JFrame parent) //方法
{
this.text = text; //局部变量传递值给成员变量
this.parent = parent;
try
{
this.isSupported = Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
} catch (Exception e)
{
this.isSupported = false;
}
setText(false);
addMouseListener(this);
}
private void setText(boolean b) //设置LinkLable的文本颜色
{
if (b)
setText("<html><font color=red><u>" + text);
else
setText("<html><font color=blue><u>" + text);
}
public void mouseEntered(MouseEvent e)
{
setText(isSupported);
if (isSupported)
setCursor(new Cursor(Cursor.HAND_CURSOR)); //光标变成手型
}
public void mouseExited(MouseEvent e)
{
setText(false);
}
public void mouseReleased(MouseEvent e)
{ }
public void mousePressed(MouseEvent e)
{ }
public void mouseClicked(MouseEvent e)
{
}
} class FixFrame extends JFrame
{
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class ResizableFrame extends JFrame
{
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class LoginFrame extends FixFrame
{
LoginFrame() //构造函数
{
display();//调用display()函数
}
private JButton btn1;
private JButton btn2;
private JTextField jtf1;
private JPasswordField jpf1; //密码文本
private ImageIcon img1;
private JLabel background1;
private ImageIcon img2;
private JLabel background2;
private JLabel lab1;
private Font fnt;
private JLabel lab2;
private Image im1;
private ImageIcon im2;
private MyListener ltn;
private BtnAction act;
private BtnAction2 act2;
class MyListener extends WindowAdapter //适配器 是扩展 不需要覆盖WindowAdapter中的所有方法 功能代码较多
{
public void windowClosing(WindowEvent e)
{
System.out.println("windowClosing");
int res = JOptionPane.showConfirmDialog(null,"是否退出程序应用","提示", JOptionPane.YES_NO_OPTION); //弹出消息框
System.out.println("res =" + res);
if(res == 0)
{
System.out.println("退出");
System.exit(1);// 退出
System.out.println("退出1"); //不输出 因为exit先执行
}
else if(res == 1)
{
System.out.println("不退出");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//System.exit(1);// 退出
// 不退出
}
}
}
class BtnAction implements ActionListener //btn事件
{
public void actionPerformed(ActionEvent e)
{
System.out.println("actionPerformed");
if(jtf1.getText().equals("jk") && jpf1.getText().equals("jk"))
{
System.out.println("OK");
dispose();
(new JFrame("主窗口")).setVisible(true);
}
else
{
System.out.println("Error");
JOptionPane.showConfirmDialog(null,"密码错误","提示", JOptionPane.DEFAULT_OPTION);
}
}
}
class BtnAction2 implements ActionListener //内部类
{
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
JButton b = (JButton)o; //强制类型转换
System.out.println("芝麻开门" + btn2.getText()); //类的成员/函数,可以在内部类中使用 if(b == btn2) //b.getSource == "重置"
{
jtf1.setText("");
jpf1.setText("");
}
}
}
public void display()
{
//JFrame frm = new JFrame(); //窗体
img1 = new ImageIcon("timg.gif"); //背景
background1 = new JLabel(img1);
this.getLayeredPane().add(background1, new Integer(Integer.MIN_VALUE));
//background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
background1.setBounds(0, 0, 425, 450);
img2 = new ImageIcon("33.gif");
background2 = new JLabel(img2);
this.getLayeredPane().add(background2, new Integer(Integer.MIN_VALUE));
background2.setBounds(0, 0, img2.getIconWidth(), img2.getIconHeight()); jtf1 = new JTextField(30); //文本
//jtf1.setColumns(10);
jtf1.setSize(200,35);
jtf1.setLocation(130,130);
jpf1 = new JPasswordField(30); //密码文本
//jpf1.setEchoChar('#'); 设置密码文本内容
jpf1.setSize(200,35);
jpf1.setLocation(130,180); lab1 = new JLabel("账号:"); //标题
fnt = new Font("Serief",Font.ITALIC+Font.BOLD,15);
lab1.setFont(fnt);
lab1.setBackground(Color.BLUE); //label的背景颜色
lab1.setOpaque(true); //label是否透明
lab1.setForeground(Color.YELLOW); //label前景色
lab2 = new JLabel("密码:");
lab1.setSize(50,30);
lab2.setSize(50,30);
lab1.setLocation(70,130);
lab2.setLocation(70,180);
btn1 = new JButton("登录");
btn1.setBounds(100,230,180,50);
im1 = (new ImageIcon("QQ.png")).getImage(); //图标
this.setIconImage(im1);
//ImageIcon im2 = new ImageIcon("77.png"); //图标
im2 = new ImageIcon("./77.png");
btn1.setIcon(im2);
this.setLayout(null); //布局--绝对布局
ltn = new MyListener(); //监听
this.addWindowListener(ltn);
act = new BtnAction(); //btn事件
btn1.addActionListener(act);
btn2 = new JButton("重置");
btn2.setBounds(300,230,100,50);
act2 = new BtnAction2();
btn2.addActionListener(act2);
//frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(425,325);
this.setLocation(700,500);
this.setTitle("QQ登录");
this.setResizable(false);
this.add(btn1);
this.add(btn2);
this.add(lab1);
this.add(lab2);
this.add(jpf1);
this.add(jtf1);
this.add(background1);
this.add(background2);
this.setVisible(true);
System.out.println("OK");
}
public static void main(String[] args)
{
LoginFrame Event1 = new LoginFrame();
System.out.println("OK");
}
}
class RegsterFrame extends FixFrame
{ }
class BackPswFrame extends FixFrame
{ }
class MainFrame extends ResizableFrame
{ }

java继承系列之添加一个LinkLable类的更多相关文章

  1. Java基础-继承-编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数 loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个 类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功 能。

    #29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight.小车类Car是Vehicle的子类,其中包含的属性有载人数 loader.卡车类T ...

  2. 学习ASP.NET Core Razor 编程系列二——添加一个实体

    在Razor页面应用程序中添加一个实体 在本篇文章中,学习添加用于管理数据库中的书籍的实体类.通过实体框架(EF Core)使用这些类来处理数据库.EF Core是一个对象关系映射(ORM)框架,它简 ...

  3. Entity Framework 的小实例:在项目中添加一个实体类,并做插入操作

    Entity Framework 的小实例:在项目中添加一个实体类,并做插入操作 1>. 创建一个控制台程序2>. 添加一个 ADO.NET实体数据模型,选择对应的数据库与表(Studen ...

  4. 为什么java源文件中只允许一个public类存在

    1.提出问题 为什么java源文件中只允许一个public类存在? 2.分析问题 问题涉及到的条件:源文件的名字    public类     main方法 一般我们在编写一个源文件的时候: 一个pu ...

  5. 为什么一个java源文件中只能有一个public类

    问题:一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 答案:可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致.一个文件 ...

  6. 浅谈为什么一个java源文件中只能有一个public类?

    声明,本篇文章为转载 转载 http://blog.csdn.net/bareheadzzq/article/details/6562211 最近在一个java文件中实现了几个类,其中一个声明为pub ...

  7. java基础—继承题目:编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish

    编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private Str ...

  8. java中使用反射做一个工具类,来为指定类中的成员变量进行赋值操作,使用与多个类对象的成员变量的赋值。

    //------------------------------------------------我是代码的分割线 // 首选是一个工具类,在该工具类里面,定义了一个方法,public void s ...

  9. 第7章 一个java源文件中只能有一个public类

    一个Java源文件中最多只能有一个public类, 1)当有一个public类时,源文件名必须与之一致,否则无法编译, 2)如果源文件中没有一个public类,则文件名与类中没有一致性要求. 至于ma ...

随机推荐

  1. C# readonly

    当某个字段是引用类型,并且该字段被标记为readonly时,不可改变的是引用,而非字段引用的对象,例如:

  2. JSONP、图片Ping、XMLHttpRequest2.0等跨域资源请求(CORS)

    跨域:当协议.主域名.子域名.端口号中任意一个不相同时都不算同一个域,而在不同域之间请求数据即为跨域请求.解决方法有以下几种(如有错误欢迎指出)以请求图片url为例: 1.通过XMLHttpReque ...

  3. Bootstrap列表与代码样式(附源码)--Bootstrap

    给大家分享下Bootstrap框架中列表与代码样式相关的知识 1.列表 (1)无序列表 <ul> <li>CN217编程</li> </ul> 注意:u ...

  4. 【学习】文本框输入监听事件oninput

    真实项目中遇到的,需求是:一个文本框,一个按钮,当文本框输入内容时,按钮可用,当删除内容时,按钮不可用. 刚开始用的focus和blur, $(".pay-text").focus ...

  5. commonjs模块和es6模块的区别

    commonjs模块与es6模块的区别 到目前为止,已经实习了3个月的时间了.最近在面试,在面试题里面有题目涉及到模块循环加载的知识.趁着这个机会,将commonjs模块与es6模块之间一些重要的的区 ...

  6. ViewPager使用记录1——展示固定数据

    ViewPager是v4支持库中的一个控件,相信几乎所有接触Android开发的人都对它不陌生.之所以还要在这里翻旧账,是因为我在最近的项目中有多个需求用到了它,觉得自己对它的认识不够深刻.我计划从最 ...

  7. LINUX 笔记-MOUNT

    mount [-t vfstype] [-o options] device dir -o options: 主要用来描述设备或档案的挂接方式 1)loop:用来把一个文件当成硬盘分区挂上系统 2)r ...

  8. Loadrunner Http接口Get/Post方法性能测试脚本解析

    最近使用LoadRunner 11进行了一次完整的Http WEB接口性能测试,下面介绍下Http接口Get/Post方法性能测试脚本通用编写方法. 1. Http接口性能测试基本流程 首先定义了一个 ...

  9. MongoDB复制

    1. 什么是复制 (1)MongoDB复制是将数据同步在多个服务器的过程. (2)复制提供了数据的冗余备份,并在多个服务器上存储数据副本,提高了数据的可用性, 并可以保证数据的安全性. (3)复制还允 ...

  10. 排序算法总结(C++版)

    总结下学过的排序算法,方便以后用到. 1.插入排序——将一个记录插入到已排序好的有序表中,从而得到一个新,记录数增1的有序表. void insertSort(int a[],int len) { ; ...