new GradientPaint(200,200,Color.red,200,180,Color.yellow); g_2d.setPaint(gradient_3); g_2d.fill(center_curve_1); } } }
public class E {
public static void main(String args[]) { JFrame f=new JFrame(); f.setSize(500,450); f.setVisible(true);
Flower canvas=new Flower(); f.add(canvas,\ f.validate();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } }
5. import java.awt.*;
import javax.swing.*; import java.awt.geom.*; class Moon extends Canvas { public void paint(Graphics g)
{ Graphics2D g_2d=(Graphics2D)g; Ellipse2D ellipse1=
new Ellipse2D. Double (20,80,60,60), ellipse2=
new Ellipse2D. Double (40,80,80,80); g_2d.setColor(Color.white); Area a1=new Area(ellipse1), a2=new Area(ellipse2); a1.subtract(a2); //\差\ g_2d.fill(a1); } }
public class E {
public static void main(String args[]) { JFrame f=new JFrame(); f.setSize(500,450); f.setVisible(true); Moon moon=new Moon(); moon.setBackground(Color.black); f.add(moon,\
f.validate();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } }
习题十五(第15章)
一、问答题
1.LinkedList使用链式存储结构,ArrayList使用顺序存储结构。
2.迭代器遍历在找到集合中的一个对象的同时,也得到待遍历的后继对象的引用,因此迭代器可以快速地遍历集合。 3.不是。
4.用HashMap
2.ABCD。 三、编写程序 1. import java.util.*;
public class E {
public static void main(String args[]) {
Stack
Integer temp=new Integer(2*f1+2*f2); System.out.println(\ stack.push(temp); stack.push(F2); k++; } } } }
2. import java.util.*;
class Student implements Comparable { int english=0; String name;
Student(int english,String name) { this.name=name; this.english=english; }
public int compareTo(Object b) { Student st=(Student)b; return (this.english-st.english); } }
public class E {
public static void main(String args[]) {
List
String name[]={\张三\李四\旺季\加戈\为哈\周和\赵李\将集\ for(int i=0;i list.add(new Student(score[i],name[i])); } Iterator TreeSet Iterator System.out.println(\ } } } 3. import java.util.*; class UDiscKey implements Comparable { double key=0; UDiscKey(double d) { key=d; } public int compareTo(Object b) { UDiscKey disc=(UDiscKey)b; if((this.key-disc.key)==0) return -1; else return (int)((this.key-disc.key)*1000); } } class UDisc{ int amount; double price; UDisc(int m,double e) { amount=m; price=e; } } public class E { public static void main(String args[ ]) { TreeMap UDisc[k]=new UDisc(amount[k],price[k]); } UDiscKey key[]=new UDiscKey[4] ; for(int k=0;k key[k]=new UDiscKey(UDisc[k].amount); } for(int k=0;k treemap.put(key[k],UDisc[k]); } int number=treemap.size(); Collection System.out.println(\元\
相关推荐: