17.6

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;

import javax.swing.*;

public class Test_17_6 extends JFrame{
    private JPanel JP1 = new JPanel();
    private JPanel JP2 = new JPanel();
    private JLabel jl1 = new JLabel("Mile");
    private JLabel jl2 = new JLabel("KiloMeter");
    private JTextField jtf1 = new JTextField(10);
    private JTextField jtf2 = new JTextField(10);
    private Double distance;

    public Test_17_6(){
        JP1.setLayout(new GridLayout(2,1));
        jtf1.setHorizontalAlignment(JTextField.RIGHT);
        jtf2.setHorizontalAlignment(JTextField.RIGHT);
        JP1.add(jl1);
        JP1.add(jl2);
        JP2.setLayout(new GridLayout(2,1));
        JP2.add(jtf1);
        JP2.add(jtf2);

        add(JP1,BorderLayout.CENTER);
        add(JP2,BorderLayout.EAST);

        //add listener
        jtf1.addKeyListener(new KeyAdapter(){

            @Override
            public void keyPressed(KeyEvent e) {
                // TODO Auto-generated method stub
                if(e.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    distance = 1.609344 * Double.parseDouble(jtf1.getText());
                    jtf2.setText(String.valueOf(distance));
                }
            }
        });
        jtf2.addKeyListener(new KeyAdapter(){

            @Override
            public void keyPressed(KeyEvent e) {
                // TODO Auto-generated method stub
                if(e.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    distance =  Double.parseDouble(jtf2.getText()) / 1.609344;
                    jtf1.setText(String.valueOf(distance));
                }
            }
        });
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Test_17_6 frame = new Test_17_6();
        frame.setTitle("Test_17_6");
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

}

时间: 2024-12-05 21:26:50

17.6的相关文章

AnimeGAN输出日志

D:\MyFiles\LearnFiles\Code\Python\AnimeGAN\AnimeGAN>python main.py --phase train --dataset Hayao --epoch 1 --init_epoch 1D:\Users\feng_\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning:

[c/c++] programming之路(17)、高级指针

一.二级指针 二级指针的作用:1.函数改变外部变量指针2.外挂改变一个指针的值 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void main(){ 5 int a = 10; 6 int b = 20; 7 int *p1 = &a; 8 int *p2 = &b; 9 int **pp = &p1; 10 printf("%d,", **pp); 11 printf("\n%x,

java核心技术 - 17个重要的知识点

1.Java中没有多继承,而是用接口来代替多继承 2.运行一个已经编译的程序时,Java解释器总是从指定类的main方法中的代码开始执行,因此,执行代码中必须有一个main函数. 3.Java是典型的强类型语言,即必须声明变量的类型,Java中有8种类型,6种数值类型(4个整数型和2个浮点型).一个字符类型和一个boolean类型. 想学习java可以来这个群,首先是二二零,中间是一四二,最后是九零六,里面有大量的学习资料可以下载. 4.强制类型转换: int nx = (int) x; //

Up to 8% free bonus for runescape 2007 gp on Rsorder as july best gift&Enjoy Telos During 7.1-7.22

Now, a small band of freedom fighters struggle to end the osrs gold  long, dark night of Daein's oppression. The big blog news of the day is that Vox Media has acquired Curbed Network. As an amulet you should be wearing an amulet of glory and if you

PSP(5.11——5.17)以及周记录

1.PSP 5.11 14:30 20:00 130 200 Cordova A Y min 5.12 9:00 14:00 100 200 Cordova A Y min 5.13 13:30 15:00 20 70 软件项目管理课 A Y min 19:00 20:00 20 40 Cordova A Y min 5.17 11:00 19:00 240 240 Cordova A Y min 2.PSP分类统计以及圆饼图 分类 A B C D 时间总计 750 0  0 0     3.周

TControl的消息覆盖函数大全(15个WM_函数和17个CM_函数,它的WndProc就处理鼠标与键盘消息)

注意,这些函数只有Private一种形式(也就是不允许覆盖,但仍在动态表格中): TControl = class(TComponent) private // 15个私有消息处理,大多是鼠标消息.注意,消息函数大多只是一个中介,且TWinControl并不重写. procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLBUTTONDOWN; procedure WMLButtonDown(var Messa

【面试题17】合并两个排序的链表

[题目描述] 输入两个递增排序的链表,合并这两个链表并使新链表中的结点是按照递增排序的. [解决方案] 用递归解决,非常简单. 我的代码实现,仅供参考: 1 public static ListNode Merge(ListNode listA, ListNode listB) 2 { 3 if (listA == null) 4 { 5 return listB; 6 } 7 else if(listB == null) 8 { 9 return listA; 10 } 11 12 ListN

Leetcode -- Day 17

substring Question 1 Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Below is my first direct solution, which looks complex in different case checking us

17.如何自学Struts2之Struts2 Annotation注释[视频]

17.如何自学Struts2之Struts2 Annotation注释[视频] 之前写了一篇"打算做一个视频教程探讨如何自学计算机相关的技术",优酷上传不了,只好传到百度云上: http://pan.baidu.com/s/1kTDsa95 有问题可以直接回复这篇文章.

Android学习系列(17)--App列表之圆角ListView(续)

http://www.cnblogs.com/qianxudetianxia/archive/2011/09/19/2068760.html 本来这篇文章想并到上篇Android学习系列(16)--App列表之圆角ListView中的,但是若是如此就让大家错过一篇新的好的文章,着实可惜.上篇中我们使用shape,corners,gradient实现了一个渐变的圆角效果,但是在完文之后的实践中,我发现有时效果不甚满意,选中和放手的事件监听没有去正确的判断,然后渐变效果也比较单一,性能也觉得不是很快