您当前的位置:首页 > 精选知识 > 正文

getmonth(java中的getMonth()函数和Calendar.get(Calendar.MONTH)函数)

并将最大值输出 */  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 》= nNumB && nNumA 》= nNumC)  {  nMax = nNumA;  }  else if (nNumB 》= nNumC && nNumB 》= nNumA)  {  nMax = nNumB;  }  else if (nNumC 》= nNumA && nNumC 》= 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“ );  }  辛苦,求java做动画代码import java.awt.Canvas;import java.awt.Color;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.Frame;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.RenderingHints;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class TestImage extends Frame{private static final long serialVersionUID = 1L;private static boolean PRESSED = false;private static int pointX = 0;private static int pointy = 200;private static int RIGHT_GO = 0;private static int LEFT_GO = 0;private static int DIR = 0;private static int ANGLE = 0;private static int W = 50;private static int H = 60;private _Canvas canvas = null;public TestImage (){add (canvas = new _Canvas ());setIgnoreRepaint (true);requestFocus ();}public class _Canvas extends Canvas implements Runnable{private static final long serialVersionUID = 1L;private BufferedImage bi = null;private Image bufferedImage = null;private Thread thread = null;private long sleepTime = 10;public _Canvas (){try{bi = ImageIO.read (new File (“go.png“));}catch (IOException e){}setBackground (Color.BLACK);requestFocus ();addKeyListener (new KeyListener (){@Overridepublic void keyTyped ( KeyEvent e ){}@Overridepublic void keyReleased ( KeyEvent e ){RIGHT_GO = 0;PRESSED = false;}@Overridepublic void keyPressed ( KeyEvent e ){// 38 40 37 39上下左右DIR = e.getKeyCode ();PRESSED = true;}});}@Overridepublic void paint ( Graphics g ){Graphics2D g2d = (Graphics2D) g;g2d.setRenderingHint (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);g2d.drawImage (rotateImage (bi.getSubimage (RIGHT_GO, LEFT_GO, W, H), ANGLE, true), pointX, pointy, W, H,this);g2d.dispose ();}@Overridepublic void update ( Graphics g ){if (null == bufferedImage){bufferedImage = createImage (getWidth (), getHeight ());}Graphics bufferedG = bufferedImage.getGraphics ();bufferedG.clearRect (0, 0, getWidth (), getHeight ());paint (bufferedG);bufferedG.dispose ();g.drawImage (bufferedImage, 0, 0, this);g.dispose ();}public void start (){thread = new Thread (this);thread.setName (“TestImage“);thread.setPriority (Thread.MIN_PRIORITY);thread.start ();}public synchronized void stop (){thread = null;notify ();}@Overridepublic void run (){Thread me = Thread.currentThread ();while (thread == me && !isShowing () || getSize ().width == 0){try{Thread.sleep (555);}catch (InterruptedException e){return;}}while (thread == me && isShowing ()){if (PRESSED){try{if (DIR == 39){RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 0;pointX = pointX + 1;if (pointX 》 420){ANGLE = 90;pointX--;pointy--;W = 60;H = 50;}if (RIGHT_GO 》 50){RIGHT_GO = 0;}}else if (DIR == 37){pointX = pointX - 1;RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 60;if (pointX 《 0){ANGLE = -90;pointX++;pointy--;W = 60;H = 50;}if (RIGHT_GO 》 50){RIGHT_GO = 0;}}else if (DIR == 38){W = 50;H = 60;pointy = 150;ANGLE = 0;RIGHT_GO = 100;}else if (DIR == 40){W = 50;H = 60;ANGLE = 0;pointy = 200;RIGHT_GO = 0;}Thread.sleep (sleepTime);repaint ();}catch (InterruptedException e){break;}}else{RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 0;pointX = pointX + 1;if (RIGHT_GO 》 50){RIGHT_GO = 0;}if (pointX 》 500){pointX = 0;}try{Thread.sleep (sleepTime);repaint ();}catch (InterruptedException e){break;}}}thread = null;}}/** * 旋转图像为指定角度 *  * @param degree * @return */public static BufferedImage rotateImage ( final BufferedImage image, final int angdeg, final boolean d ){int w = image.getWidth ();int h = image.getHeight ();int type = image.getColorModel ().getTransparency ();BufferedImage img;Graphics2D graphics2d;( graphics2d = ( img = new BufferedImage (w, h, type) ).createGraphics () ).setRenderingHint (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);graphics2d.rotate (d ? -Math.toRadians (angdeg) : Math.toRadians (angdeg), w / 2, h / 2);graphics2d.drawImage (image, 0, 0, null);graphics2d.dispose ();return img;}public static void main ( String args ){EventQueue.invokeLater (new Runnable (){@Overridepublic void run (){final TestImage ti = new TestImage ();ti.setSize (new Dimension (500, 300));ti.setLocationRelativeTo (null);ti.addWindowListener (new WindowAdapter (){@Overridepublic void windowClosing ( WindowEvent e ){System.exit (0);}@Overridepublic void windowDeiconified ( WindowEvent e ){ti.canvas.start ();}@Overridepublic void windowIconified ( WindowEvent e ){ti.canvas.stop ();}});ti.setResizable (false);ti.canvas.start ();ti.setVisible (true);}});}}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(“128 & 129 = “ + (128 & 129));  System.out.println(“56 | 32 = “ + (56 | 32));  System.out.println(“27 ^ 123 = “ + (27 ^ 123));  }  }  /** * Created by y0n on 2017/4/17. * 3.从键盘上输入3个数,java中的getMonth()函数和Calendar.get(Calendar.MONTH)函数Date d = new Date();Calendar c = Calendar.getInstance();c.setTime(d);System.out.println(c.get(Calendar.MONTH));一月对应0十二月对应11javaswing中怎样使用绝对布局Swing 中窗体具有默认的布局管理器,即不使用任何布局管理器,虽然布局管理器能够简化程序的开发,是哦那个该布局的步骤如下:(1) 使用Container.setLayout(null)方式取消布局管理器,求出这三个数字中的最大值,但是为了获取最大的灵活性。

java中的getMonth()函数和Calendar.get(Calendar.MONTH)函数

Date d = new Date();Calendar c = Calendar.getInstance();c.setTime(d);System.out.println(c.get(Calendar.MONTH));一月对应0十二月对应11

javaswing中怎样使用绝对布局

Swing 中窗体具有默认的布局管理器,如JFrame 使用是边界布局。虽然布局管理器能够简化程序的开发,但是为了获取最大的灵活性,可以使用绝对布局,即不使用任何布局管理器,是哦那个该布局的步骤如下:

(1) 使用Container.setLayout(null)方式取消布局管理器。

(2)使用Component.setBounds()方法来设置每个控件的大小与位置。

求java做动画代码

import java.awt.Canvas;import java.awt.Color;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.Frame;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.RenderingHints;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class TestImage extends Frame{private static final long serialVersionUID = 1L;private static boolean PRESSED = false;private static int pointX = 0;private static int pointy = 200;private static int RIGHT_GO = 0;private static int LEFT_GO = 0;private static int DIR = 0;private static int ANGLE = 0;private static int W = 50;private static int H = 60;private _Canvas canvas = null;public TestImage (){add (canvas = new _Canvas ());setIgnoreRepaint (true);requestFocus ();}public class _Canvas extends Canvas implements Runnable{private static final long serialVersionUID = 1L;private BufferedImage bi = null;private Image bufferedImage = null;private Thread thread = null;private long sleepTime = 10;public _Canvas (){try{bi = ImageIO.read (new File (“go.png“));}catch (IOException e){}setBackground (Color.BLACK);requestFocus ();addKeyListener (new KeyListener (){@Overridepublic void keyTyped ( KeyEvent e ){}@Overridepublic void keyReleased ( KeyEvent e ){RIGHT_GO = 0;PRESSED = false;}@Overridepublic void keyPressed ( KeyEvent e ){// 38 40 37 39上下左右DIR = e.getKeyCode ();PRESSED = true;}});}@Overridepublic void paint ( Graphics g ){Graphics2D g2d = (Graphics2D) g;g2d.setRenderingHint (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);g2d.drawImage (rotateImage (bi.getSubimage (RIGHT_GO, LEFT_GO, W, H), ANGLE, true), pointX, pointy, W, H,this);g2d.dispose ();}@Overridepublic void update ( Graphics g ){if (null == bufferedImage){bufferedImage = createImage (getWidth (), getHeight ());}Graphics bufferedG = bufferedImage.getGraphics ();bufferedG.clearRect (0, 0, getWidth (), getHeight ());paint (bufferedG);bufferedG.dispose ();g.drawImage (bufferedImage, 0, 0, this);g.dispose ();}public void start (){thread = new Thread (this);thread.setName (“TestImage“);thread.setPriority (Thread.MIN_PRIORITY);thread.start ();}public synchronized void stop (){thread = null;notify ();}@Overridepublic void run (){Thread me = Thread.currentThread ();while (thread == me && !isShowing () || getSize ().width == 0){try{Thread.sleep (555);}catch (InterruptedException e){return;}}while (thread == me && isShowing ()){if (PRESSED){try{if (DIR == 39){RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 0;pointX = pointX + 1;if (pointX 》 420){ANGLE = 90;pointX--;pointy--;W = 60;H = 50;}if (RIGHT_GO 》 50){RIGHT_GO = 0;}}else if (DIR == 37){pointX = pointX - 1;RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 60;if (pointX 《 0){ANGLE = -90;pointX++;pointy--;W = 60;H = 50;}if (RIGHT_GO 》 50){RIGHT_GO = 0;}}else if (DIR == 38){W = 50;H = 60;pointy = 150;ANGLE = 0;RIGHT_GO = 100;}else if (DIR == 40){W = 50;H = 60;ANGLE = 0;pointy = 200;RIGHT_GO = 0;}Thread.sleep (sleepTime);repaint ();}catch (InterruptedException e){break;}}else{RIGHT_GO = RIGHT_GO + 50;LEFT_GO = 0;pointX = pointX + 1;if (RIGHT_GO 》 50){RIGHT_GO = 0;}if (pointX 》 500){pointX = 0;}try{Thread.sleep (sleepTime);repaint ();}catch (InterruptedException e){break;}}}thread = null;}}/** * 旋转图像为指定角度 *  * @param degree * @return */public static BufferedImage rotateImage ( final BufferedImage image, final int angdeg, final boolean d ){int w = image.getWidth ();int h = image.getHeight ();int type = image.getColorModel ().getTransparency ();BufferedImage img;Graphics2D graphics2d;( graphics2d = ( img = new BufferedImage (w, h, type) ).createGraphics () ).setRenderingHint (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);graphics2d.rotate (d ? -Math.toRadians (angdeg) : Math.toRadians (angdeg), w / 2, h / 2);graphics2d.drawImage (image, 0, 0, null);graphics2d.dispose ();return img;}public static void main ( String args ){EventQueue.invokeLater (new Runnable (){@Overridepublic void run (){final TestImage ti = new TestImage ();ti.setSize (new Dimension (500, 300));ti.setLocationRelativeTo (null);ti.addWindowListener (new WindowAdapter (){@Overridepublic void windowClosing ( WindowEvent e ){System.exit (0);}@Overridepublic void windowDeiconified ( WindowEvent e ){ti.canvas.start ();}@Overridepublic void windowIconified ( WindowEvent e ){ti.canvas.stop ();}});ti.setResizable (false);ti.canvas.start ();ti.setVisible (true);}});}}

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(“128 & 129 = “ + (128 & 129));  

  • 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 》= nNumB && nNumA 》= nNumC)  

  • {  

  • nMax = nNumA;  

  • }  

  • else if (nNumB 》= nNumC && nNumB 》= nNumA)  

  • {  

  • nMax = nNumB;  

  • }  

  • else if (nNumC 》= nNumA && nNumC 》= 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“ );  

  • }  

辛苦,望采纳!老铁


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: 直男适合什么样的女孩

下一篇: 生活垃圾怎么处理



推荐阅读