Bootstrap

java二级----操作题

内部类
1:Graphics类
例子:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyFrame extends JFrame {
	private static final long serialVersionUID = 1L; 
	class MyPanel extends JPanel {
		private static final long serialVersionUID = 1L;
		public void paint(Graphics graphics) {
			super.paint(graphics);
			Graphics g2d = (Graphics2D) graphics;
			g2d.setColor(Color.black);
			g2d.draw3DRect(0, 0, 400, 500, true);
 }
 }
public MyFrame() {
	this.add(new MyPanel());
	this.setSize(800, 600);
} 
public static void main(String[] args) {
	MyFrame frame = new MyFrame(); 
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
	frame.setVisible(true);
 }
}


在这里插入图片描述

import java.awt.Graphics;
import javax.swing.JFrame;
public class Test extends JFrame{
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawRect(60, 50, 100, 100);
}
private void win() {
this.setVisible(true);
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Test f = new Test();
 f.win();
}
}

在这里插入图片描述

2:Java Applet基础讲解

地址

3:
在这里插入图片描述
代码:

//*********Found**********
import javax.swing.JOptionPane;

public class Test{
   public static void main( String args[] ){
      String s1, s2, s3, s4, output;
      s1 = new String( "hello" );
      s2 = new String( "good bye" );
      s3 = new String( "Happy Birthday" );
      s4 = new String( "happy birthday" );
      output = "s1 = " + s1 + "\ns2 = " + s2 +
               "\ns3 = " + s3 + "\ns4 = " + s4 + "\n\n";
  
      if ( s1.equals( "hello" ) )
         //*********Found**********
         output = output + "s1 equals \"hello\"\n";
      else
         output = output + "s1 does not equal \"hello\"\n"; 
      
      if ( s1 == "hello" )
         output += "s1 equals \"hello\"\n";
      else
         output += "s1 does not equal \"hello\"\n";
      if ( s3.equalsIgnoreCase( s4 ) )
         output += "s3 equals s4\n";
      else
         output += "s3 does not equal s4\n";
      
      output +=
         "\ns1.compareTo( s2 ) is " + s1.compareTo( s2 ) +
         "\ns2.compareTo( s1 ) is " + s2.compareTo( s1 ) +
         "\ns1.compareTo( s1 ) is " + s1.compareTo( s1 ) +
         "\ns3.compareTo( s4 ) is " + s3.compareTo( s4 ) +
         "\ns4.compareTo( s3 ) is " + s4.compareTo( s3 ) +
         "\n\n";
   
      if ( s3.regionMatches( 0, s4, 0, 5 ) )
         output += "First 5 characters of s3 and s4 match\n";
      else
         output +=
            "First 5 characters of s3 and s4 do not match\n";

      if ( s3.regionMatches( true, 0, s4, 0, 5 ) )
         output += "First 5 characters of s3 and s4 match";
      else
         output +=
            "First 5 characters of s3 and s4 do not match";
      //*********Found**********
      JOptionPane.showMessageDialog( null, output,
         "333",
         JOptionPane.INFORMATION_MESSAGE );
    System.exit( 0 );
  }  
}

效果:
在这里插入图片描述
注:
JoptionPane对话框四种类型:
1): showMessageDialog:向用户显示一些信息
2): showConfirmDialog:问一个要求确认的问题并得到yes/no/cancel响应。
3): showInputDialog:提示用户进行输入
4): showOptionDialog:可选择的对话框。

3:线程

在这里插入图片描述

//*********Found**********
public class Java_2 implements Runnable{ 
   private int x=0; 
   private int y=0; 
 
   public static void main(String[]args){
      Java_2 r = new Java_2();
      //*********Found********** 
      Thread t = new Thread( r );
      t.start(); 
   }
   public void run() { 
      //*********Found**********
      int k = 0;
      for(;;){		
         x++; 
         //*********Found**********
         y++; 
         k++;
         if (k>5) break;
         System.out.println("x=" + x + ",y ="+ y); 
      }
   }
}

解析:
创建线程的两种方式:
1)实现Runnabl接口
2)继承Thread类。
都要重写run方法。

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;