import java.awt.Color;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import javax.swing.JFrame;public class MyFrame {public static void main(String[] args) {JFrame frame = new JFrame("我的第一个Frame");//标题frame.setSize(500 , 1000);//宽和高frame.getContentPane().setBackground(Color.RED);//颜色frame.setVisible(true);BufferedReader intemp = new BufferedReader(new InputStreamReader(System.in));System.out.println("Press return key to exit.");try{String s = intemp.readLine();} catch(IOException e){System.out.println("IOException");}System.exit(0);//退出}//main 结束}

import java.awt.Color;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import javax.swing.JFrame;import javax.swing.JPanel;public class FrameWithPanelTest {public static void main(String[] args) {JFrame frame = new JFrame("My Frame");frame.setSize(500 , 500);frame.getContentPane().setBackground(Color.BLACK);frame.setVisible(true);JPanel contentPane = new JPanel();contentPane.setSize(100 , 100);contentPane.setBackground(Color.yellow);frame.add(contentPane);frame.setLayout(null); //不加上这一句设置布局,contentPanel会铺满整个frameBufferedReader intemp = new BufferedReader(new InputStreamReader(System.in));System.out.println("Press return key to exit.");try{String s = intemp.readLine();} catch(IOException e){System.out.println("IOException");}System.exit(0);}}

package classroom;
//public class Thread extends Object implements Runnableimport java.awt.Color;import java.awt.FlowLayout;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;public class FrameWithPanelTest {public static void main(String[] args) {JFrame frame = new JFrame("My Frame");frame.setSize(500 , 500);frame.getContentPane().setBackground(Color.BLACK);frame.setLayout(new FlowLayout(FlowLayout.CENTER , 50 , 50)); //为JFrame顶层容器设置FlowLayout布局管理器JPanel contentPane = new JPanel();contentPane.setSize(100 , 100);//内部按钮对齐方式,水平和垂直间距contentPane.setLayout(new FlowLayout(FlowLayout.CENTER , 50 , 50)); //为Japnel设置布局管理器contentPane.setBackground(Color.yellow);JButton btn1 , btn2 , btn3 ; //定义3个按钮btn1 = new JButton("打开");btn2 = new JButton("关闭");btn3 = new JButton("返回");contentPane.add(btn1);contentPane.add(btn2);contentPane.add(btn3);frame.add(contentPane);frame.setVisible(true); //显示JFrameBufferedReader intemp = new BufferedReader(new InputStreamReader(System.in));System.out.println("Press return key to exit.");try{String s = intemp.readLine();} catch(IOException e){System.out.println("IOException");}System.exit(0);}}

package classroom;
//public class Thread extends Object implements Runnableimport java.awt.BorderLayout;import java.awt.Container;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionListener;import javax.swing.JFrame;import javax.swing.JLabel;//鼠标及按键public class MouseControl implements MouseMotionListener , KeyListener{private JFrame frame;private JLabel tf;String ch = ""; //放置待显示的字符public static void main(String[] args){MouseControl two = new MouseControl();two.go();}private void go() {frame = new JFrame("鼠标按键测试");Container contentPane = frame.getContentPane();contentPane.add(new JLabel("get mouse and keyboard event") , BorderLayout.NORTH);tf = new JLabel();contentPane.add(tf, BorderLayout.SOUTH);//注册监听程序frame.addMouseMotionListener(this);frame.addKeyListener(this);frame.setSize(300 , 300);frame.setVisible(true);}//接下来为实现接口中的方法@Overridepublic void keyTyped(KeyEvent e) { //顺序 keypress keytype keyrelease// TODO Auto-generated method stubSystem.out.println("2");int charcode = e.getKeyCode();ch = "有键按下2";if(charcode == KeyEvent.VK_SHIFT) {ch = "shift2";}if(charcode == KeyEvent.VK_CONTROL) ch = "control2";}@Overridepublic void keyPressed(KeyEvent e) { //看不到显示,因为keytype覆盖了// TODO Auto-generated method stubSystem.out.println("1");int charcode = e.getKeyCode();ch = "有键按下1";if(charcode == KeyEvent.VK_SHIFT) ch = "shift1";if(charcode == KeyEvent.VK_CONTROL) ch = "control1";}@Overridepublic void keyReleased(KeyEvent e) {// TODO Auto-generated method stub//ch = "有键松开";System.out.println("3");}@Overridepublic void mouseDragged(MouseEvent e) { //按住鼠标拖动才会调用// TODO Auto-generated method stubString s = "鼠标拖动的坐标: X =" +e.getX() + " Y =" + e.getY() + " KEY:" + ch;tf.setText(s);}@Overridepublic void mouseMoved(MouseEvent e) {// TODO Auto-generated method stubString s = "鼠标移动时的坐标: X =" +e.getX() + " Y =" + e.getY() + " KEY:" + ch;tf.setText(s);}}

jframe的简单用法相关推荐

  1. java的setbounds_java Swing组件setBounds()简单用法实例分析

    本文实例讲述了java Swing组件setBounds()简单用法.分享给大家供大家参考,具体如下: 先看API: public void setBounds(Rectangle r) 移动组件并调 ...

  2. 反编译工具jad简单用法

    反编译工具jad简单用法 下载地址: [url]http://58.251.57.206/down1?cid=B99584EFA6154A13E5C0B273C3876BD4CC8CE672& ...

  3. QCustomPlot的简单用法总结

    QCustomPlot的简单用法总结 第一部分:QCustomPlot的下载与安装 第二部分:QCustomPlot在VS2013+QT下的使用 QCustomPlot的简单用法总结    写在前面, ...

  4. python matplotlib 简单用法

    python matplotlib 简单用法 具体内容请参考官网 代码 import matplotlib.pyplot as plt import numpy as np # 支持中文 plt.rc ...

  5. Windump网络命令的简单用法

    Windump网络命令的简单用法 大家都知道,unix系统下有个tcpdump的抓包工具,非常好用,是做troubleshooting的好帮手.其实在windows下也有一个类似的工作,叫windum ...

  6. Android TabLayout(选项卡布局)简单用法实例分析

    本文实例讲述了Android TabLayout(选项卡布局)简单用法.分享给大家供大家参考,具体如下: 我们在应用viewpager的时候,经常会使用TabPageIndicator来与其配合.达到 ...

  7. shell expect的简单用法

    为什么需要expect?     我们通过Shell可以实现简单的控制流功能,如:循环.判断等.但是对于需要交互的场合则必须通过人工来干预,有时候我们可能会需要实现和交互程序如 telnet服务器等进 ...

  8. Shellz中awk的简单用法

    其实shell脚本的功能常常被低估.在实际应用中awk sed 等用法可以为shell提供更为强大的功能.下面我们将一下awk调用的简单方法进行了总结.方便同学们学习: awk的简单用法: 第一种调用 ...

  9. python装饰器实例-Python装饰器原理与简单用法实例分析

    本文实例讲述了Python装饰器原理与简单用法.分享给大家供大家参考,具体如下: 今天整理装饰器,内嵌的装饰器.让装饰器带参数等多种形式,非常复杂,让人头疼不已.但是突然间发现了装饰器的奥秘,原来如此 ...

最新文章

  1. 【seaborn】(1) 数据可视化,绘图风格、布局
  2. 自己挖坑自己填,谷歌大改Transformer注意力,速度、内存利用率都提上去了
  3. 深度历险:Redis 内存模型详解
  4. pandas的基本使用
  5. 函数指针也可作为函数的参数
  6. rabbitmq接口异常函数方法_分布式系统消息中间件——RabbitMQ的使用进阶篇
  7. 上海java 开发培训_上海十大java培训
  8. 蓝桥杯 ADV-91 算法提高 素数判断
  9. 从多路搜索树到 B-树
  10. 20190901每日一句 那就从现在开始吧,让生命变得更有价值
  11. [转] 香港流行乐坛三十年
  12. Python学生信息管理系统(增删查改、模糊查找、txt文件输出)# 谭子
  13. OKHttp源码解析 (复用连接池)
  14. 短信验证码接收不到原因和解决方案分析
  15. Complex-Valued CNN and Its Application in Polarimetric SAR Image Classification
  16. littleVGL学习笔记8——lv_cont 容器
  17. 图文并茂:推荐算法架构——粗排
  18. Windows安装pyserial
  19. 软银巨资收购ARM:这是场天作之合?
  20. 【未解决】局域网内通过MAC查看服务器IP

热门文章

  1. 3 个独特的简历生成器,开源了!
  2. Unity3D游戏开发之Unity3D中的动态阴影
  3. (程序员情感三部曲之三)程序员与女朋友相处之道
  4. mongoDB 定长集合(capped collection)
  5. 电脑录屏怎么录制影视片段视频
  6. 解决T2A W2A A2W的报错error C2065 lpw 未声明的标识符
  7. [ 人机交互 ]第一次作业 2015080360025秦嘉颍
  8. 关于我博客搬迁的公告
  9. word文档显示文件已损坏打不开怎么办呢?
  10. 39、【斯纳克图书馆管理系统】 财务查询