java系列代码大全 java 代码简洁( 二 )


new gongnengJF().setVisible(true);
}
});
}
// Variables declaration - do not modify
//私有的成员属性 , 定义GUI图形界面的按钮,菜单等 。
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
Swing是一组Java程序元件,它能够创建图象用户接口(GUI)元件 , 如按钮和滚动条,它们独立于特定操作系统的开窗口系统 。Swing元件使用Java Foundation Classes(JFC) 。
new gongnengJF().setVisible(true);
this.setVisible(false);
通过new 创建的对象,与this不是同一个对象 。
鼠标监听事件,包括单击,双击等 。。。
java代码* Created by y0n on 2017/4/17.
* 1.输出控制台传递的默认参数
*/
public class JavaDay001_1 {
public static void main(String[] args) {
System.out.println(args);
}
}
/**
* Created by y0n on 2017/4/17.
* 2.编程求表达式的结果
*/
public class JavaDay001_2 {
public static void main(String[] args) {
System.out.println("128129 = " + (128129));
System.out.println("56 | 32 = " + (56 | 32));
System.out.println("27 ^ 123 = " + (27 ^ 123));
}
}
/**
* Created by y0n on 2017/4/17.
* 3.从键盘上输入3个数,求出这三个数字中的最大值,并将最大值输出
*/
import java.util.Scanner;
public class JavaDay001_3 {
public static void main(String[] args) {
System.out.println("请输入3个数:");
Scanner scanner = new Scanner(System.in);
int nNumA = scanner.nextInt();
int nNumB = scanner.nextInt();
int nNumC = scanner.nextInt();
int nMax = 0;
if (nNumA = nNumBnNumA = nNumC)
{
nMax = nNumA;
}
else if (nNumB = nNumCnNumB = nNumA)
{
nMax = nNumB;
}
else if (nNumC = nNumAnNumC = nNumB)
{
nMax = nNumC;
}
else
{
System.out.println("无法比较!");
}
System.out.println("Max = " + nMax);
}
}
/**
* Created by y0n on 2017/4/17.
* 4.编写万年历小程序
* 输出结果:
* 请输入年:2016
* 请输入月:6
* 2016年非润年
* 2016年6月份的天数是30
*/
import com.sun.webkit.BackForwardList;
import java.util.Scanner;
public class JavaDay001_4 {
public static void main(String[] args) {
System.out.println("请输入年:");
Scanner scanner = new Scanner(System.in);
int nYear = scanner.nextInt();
System.out.println("请输入月:");
int nMounth = scanner.nextInt();
int nflag = 0;
if (nYear % 4 == 0)
{
if (nYear % 100 == 0)
{
if (nYear % 400 == 0)
{
nflag = 1;
System.out.println(nYear + "年是润年");
}
else
{
System.out.println(nYear + "年不是润年");
}
}
else
{
nflag = 1;
System.out.println(nYear + "年不是润年");
}
}
else
{
System.out.println(nYear + "年不是润年");
}
//判断2016年月份的天数
if (nMounth == 1
|| nMounth == 3
|| nMounth == 5
|| nMounth == 7
|| nMounth == 8
|| nMounth == 10
|| nMounth == 12 )
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:31" );
}
else if (nMounth == 4
|| nMounth == 6
|| nMounth == 9
|| nMounth == 11)
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:30" );

推荐阅读