Zozo

IOTAT培训:实战训练1

一、要求

使用swing做一个PC端界面程序,窗口标题为“测试窗口”;界面中加入一个按钮,按钮上的字样为“测试按钮”。

二、思维鱼骨图:

 

三、Code 样板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package qiuyu.SwingTest.EasyWindow;

import java.awt.Panel;

import javax.swing.*;

/**
* @author Created By Qiuyu
* @E-mail 1411770819@qq.com
* @date 2018年8月6日
* @function 代码实例,一个简单的窗口程序
*/

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //创建顶层容器
        //顶层容器属性设置
        //创建中间容器
        //创建基本组件
        //将基本组件添加到中间容器
        //将中间容器作为顶层容器的内容面板设置到串口(将中间容器添加到顶层容器)
        //显示窗口
    }
}

四、完整Code(稍后更新)

Foreword about Swing

Seems that Java is rarely used in PC interface developing, we may choose QT, MFC, .NET and so on. So many tools available, and they are both powerful and convenient!

I was recently told to teach swing for new students in the lab, so I spent a few days learning about it.

Differ from other tools in PC interface developing, swing is very easy to get started! The following is excerpted from Wikipedia.

Example Swing widgets in Java Swing is a GUI widget toolkit for Java. It is part of Oracle’s Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs. Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). Swing provides a look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to familiar components such as buttons, check boxes and labels, Swing provides several advanced components such as tabbed panel, scroll panes, trees, tables, and lists. Unlike AWT components, Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and therefore are platform-independent. The term “lightweight” is used to describe such an element.Swing(Java)-Wikipedia

Swing is supported in native Java, it goes with no need for extra tools as long as Java environment configured correctly.

In the following a few days, I will go on learning about it and prepare my presentation PPT. I’ll also update my blogs for the convenience of teaching, so, they’ll be posted in Chinese.

Cool Skills: Launch applications from command line in Windows

Most of the time, we launch an application by double-clicking its icon on desktop. How about doing that in a special way? A way that makes you different from everyone around you, a way that is more convenient sometimes, a way that is more coder-styled, the most important, a way that makes launching an application become a COOL thing!

Questions to forward, well at first, I’d like to show you how I lunch an application from a command line:

As you can see, firstly, press down win+r, input cmd, and then hit Enter, the command window turns up. I launched chrome by inputting start chrome, and then, hit Enter. Soonly, the chrome window showed up. So, how do I launch it by typing start chrome in command line? Well actually, this is very simple, all you need to do is to move or copy your applications’ launching shortcuts into a single folder, then, add the folder’s path to environment variables. The command START is a built-in command in Windows, use it to execute an executable file(.exe), you’ll get it launched!

Gather your launching shortcut into a single folder

For example, I move my Chrome shortcut into a folder and renamed it to “chrome”, the folder’s path is “E:\path”. Don’t forget the path!

Add the path to environment variables

There is a variable named “path” in environment variables, add “E:\path” to path.

E:\path

Verify it!

If you did everything right, input start chrome and hit Enter in command line, Chrome browser should appear.

 

Also, you can create a shortcut of your path folder, rename it like “openpath”(this is how I did it), and move it into this folder itself! So when you need open this folder to add or remove shortcuts, you can simply input start openpath, the folder will show up immediately!

The transformation of urllib2’s usage in Python3

Usage of urllib2 in Python

In Python, we can simply type the following code to import urllib2:

1
import urllib2

Then, urllib2.Request(host) and urllib2.urlopen(request) is available to use:

1
2
request = urllib2.Request(host)
response = urllib2.urlopen(request)

But, when it comes to Python3, a newer version of Python which has a lot differences with Python2, things gonna has to change!

Usage of urllib2 in Python3

In Python3, we cannot just type “import urllib2” to get it done, you’ll find an error message “No module named urllib2“. This is because of a different usage of urllib2 in python3. The following is my current solution:

Use the following code to import:

1
from urllib.request import Request

Then, here is how I use them:

1
2
request=Request(host)
response=urllib.request.urlopen(request)

Conversion between Timestamp and date, Java-based.

Sometimes, we need to do some conversions between timestamp and date. Here are my solutions.

1. Converting date to timestamp


1
2
3
4
5
6
public static long dateToStamp(String s) throws ParseException{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        return ts;
}

2.Converting timestamp to date


1
2
3
4
5
6
7
public static String stampToDate(long s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(s);
        res = simpleDateFormat.format(date);
        return res;
}

 

Don’t forget to import  java.util.Date and  java.text.SimpleDateFormat.

如何恢复内存卡的分区

由于内存卡被分区,无法使用windows磁盘管理的扩展卷将其恢复,需要借助到分区助手来合并。

打开分区助手,选中磁盘,在左方分区操作,点击擦除硬盘

 

此时开始擦除,等待时间较长。

 

 

擦除完毕,此时还需要对内存卡格式化一下就好了。