求编一段java程序

1、编写字符界面或图形界面程序,输入一个学生的三门课的成绩,计算其平均成绩,输出三门课成绩及平均成绩。每门课的成绩从键盘输入,成绩范围40~100。3、设计一个直角坐标系... 1、编写字符界面或图形界面程序,输入一个学生的三门课的成绩,计算其平均成绩,输出三门课成绩及平均成绩。每门课的成绩从键盘输入,成绩范围40~100。
3、设计一个直角坐标系上的点类Point,可实现功能:显示点的坐标、求两点间的距离。
在主类定义两个点类的对象,输出这两点的坐标值及两点间的距离。
4、设计一个一维数组类,实现功能:排序、查找最大值、查找给定数据(若有,则指出是第几个,若无,给出相应信息)。在主类测试这些功能的实现。
7、编写图形界面程序,输出各种图形,如:直线、矩形、圆角矩形、圆、椭圆等,使用不同颜色。
9、编写一个Applet,显示一行向上滚动的文字。

以上问题任选一个,不要太复杂拉~~
谢谢啦~~~
要用eclipse环境开发,高手看到的就帮帮忙吧~~在下会感激不尽的。
展开
 我来答
祚胤17
2010-05-29 · TA获得超过786个赞
知道大有可为答主
回答量:1148
采纳率:82%
帮助的人:594万
展开全部
给你个时钟吧~~
7.GDI+时钟
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Clock extends JComponent {
private static final Color INTEGRAL_COLOR = new Color(0, 128, 128);
private int radius;
private Calendar currentTime = Calendar.getInstance();
private double s = 0.03;
public Clock(int radius) {
this.radius = radius;
}
public void setCurrentTime(Date time)
{
this.currentTime.setTime(time);
}
public void setCurrentTime(long millis) {
this.currentTime.setTimeInMillis(millis);
}
public Dimension getPreferredSize() {
Insets insets = getInsets();
int r = (int) (radius == -1 ? 0 : radius * (1 + s)) + 1;
return new Dimension(r * 2 + insets.left + insets.right, r * 2
+ insets.top + insets.bottom);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Insets insets = getInsets();
int wid = getWidth() - insets.left - insets.right;
int hei = getHeight() - insets.top - insets.bottom;
int r = (int) ((Math.min(wid, hei)) / 2 / (1 + s));
g2d.translate(insets.left + r * (1 + s), insets.top + r * (1 + s));
g2d.scale(1, -1);
for (int i = 0; i < 60; i++) {
int angle = 90 - i * 6;
double pos[] = calcPos(r, angle);
paintMinuteDot(r, g2d, pos[0], pos[1], i % 5 == 0);
}
paintHourPointer(r, g2d);
paintMinutePointer(r, g2d);
paintSecondPointer(r, g2d);
paintCenterPoint(g2d);
g2d.scale(1, -1);
g2d.translate(-insets.left - r * (1 + s), -insets.top - r * (1 + s));
}
private void paintCenterPoint(Graphics2D g2d) {
g2d.setColor(Color.BLUE);
Rectangle2D rect = new Rectangle2D.Double(-2, -2, 4, 4);
g2d.fill(rect);
}
private void paintMinutePointer(int r, Graphics2D g2d) {
int minute = currentTime.get(Calendar.MINUTE);
int second = currentTime.get(Calendar.SECOND);
double angle = 90 - (minute + second / 60.0) * 6;
Shape pointerShape = createPointerShape(r * 0.8, r * 0.04, r * 0.08,
angle);
g2d.setColor(Color.LIGHT_GRAY);
g2d.fill(pointerShape);
g2d.setColor(Color.DARK_GRAY);
g2d.draw(pointerShape);
}
private void paintHourPointer(int r, Graphics2D g2d) {
int hour = currentTime.get(Calendar.HOUR);
int minute = currentTime.get(Calendar.MINUTE);
int second = currentTime.get(Calendar.SECOND);
double angle = 90 - (hour + minute / 60.0 + second / 3600.0) * 30;
Shape pointerShape = createPointerShape(r * 0.6, r * 0.06, r * 0.1,
angle);
g2d.setColor(Color.LIGHT_GRAY);
g2d.fill(pointerShape);
g2d.setColor(Color.DARK_GRAY);
g2d.draw(pointerShape);
}
private Shape createPointerShape(double r1, double r2, double r3,
double angle) {
GeneralPath gp = new GeneralPath();
double[] pos = calcPos(r1, angle);
double[] pos1 = calcPos(r2, angle + 90);
gp.append(new Line2D.Double(pos[0], pos[1], pos1[0], pos1[1]), true);
double[] pos2 = calcPos(r3, angle + 180);
gp.lineTo((float) pos2[0], (float) pos2[1]);
double[] pos3 = calcPos(r2, angle + 270);
gp.lineTo((float) pos3[0], (float) pos3[1]);
gp.closePath();
return gp;
}
private void paintSecondPointer(int r, Graphics2D g2d) {
g2d.setColor(Color.BLACK);
int second = currentTime.get(Calendar.SECOND);
int angle = 90 - second * 6;
double pos[] = calcPos(r * 0.9, angle);
double pos1[] = calcPos(r * 0.2, angle + 180);
Line2D line = new Line2D.Double(pos1[0], pos1[1], pos[0], pos[1]);
g2d.draw(line);
}
private void paintMinuteDot(int r, Graphics2D g2d, double x, double y,
boolean flag) {
g2d.setColor(flag ? Color.RED : Color.BLACK);
if (flag) {
// Rectangle2D rect = new Rectangle2D.Double(
Ellipse2D rect = new Ellipse2D.Double(x - r * s, y - r * s, r * s
* 2, r * s * 2);
g2d.fill(rect);
} else {
// Rectangle2D rect = new Rectangle2D.Double(
Ellipse2D rect = new Ellipse2D.Double(x - r * 0.02, y - r * 0.02,
r * 0.04, r * 0.04);
g2d.fill(rect);
}
}
private double[] calcPos(double r, double angle) {
double radian = Math.toRadians(angle);
double x = r * Math.cos(radian);
double y = r * Math.sin(radian);

return new double[] { x, y };
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
final Clock clock = new Clock(50);
clock.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JFrame f = new JFrame("GDI+时钟");
// f.setBounds(380,200,500,600);
f.this.add(clock, BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
clock.setCurrentTime(System.currentTimeMillis());
clock.repaint();
}
}
}.start();
}
}
mzocean
2010-05-31 · TA获得超过1083个赞
知道小有建树答主
回答量:492
采纳率:33%
帮助的人:469万
展开全部
第一题:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class MyFrame extends JFrame implements ActionListener{
JPanel jp=new JPanel(new GridLayout(3,1))
,jpb=new JPanel(new FlowLayout(FlowLayout.CENTER))
,jp1=new JPanel(new FlowLayout(FlowLayout.CENTER))
,jp2=new JPanel(new FlowLayout(FlowLayout.CENTER))
,jp3=new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton b=new JButton("确定");
JLabel jl1=new JLabel("第一门成绩:"),jl2=new JLabel("第二门成绩:"),jl3=new JLabel("第三门成绩:");
JTextField jtf1=new JTextField(15),jtf2=new JTextField(15),jtf3=new JTextField(15);
JTextArea jta=new JTextArea("成绩在40~100之间",4,15);
public MyFrame(){
super("计算成绩");
this.setLayout(new GridLayout(3,1));
jp1.add(jl1);jp1.add(jtf1);
jp2.add(jl2);jp2.add(jtf2);
jp3.add(jl3);jp3.add(jtf3);
jpb.add(b);
jp.add(jp1);jp.add(jp2);jp.add(jp3);
this.add(jp);this.add(jpb);this.add(jta);
b.addActionListener(this);
this.setSize(400,300);
this.setLocation(300,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
int i1,i2,i3;float aver;
if(e.getSource()==b){
try{i1=Integer.parseInt(jtf1.getText());
i2=Integer.parseInt(jtf2.getText());
i3=Integer.parseInt(jtf3.getText());
if((i1<40||i1>100)||(i2<40||i2>100)||(i3<40||i3>100))
throw new NumberFormatException();
}catch(NumberFormatException e1){
jta.setText("输入有误!");return;
}
aver=(float)(i1+i2+i3)/3;
jta.setText("三门成绩分别为"+i1+"、"+i2+"、"+i3+",平均成绩为"+aver+"。");
}
}
}
public class TestStudent{
public static void main (String[] args) {
new MyFrame();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
dongrenfei21
2010-05-29 · TA获得超过2926个赞
知道小有建树答主
回答量:1264
采纳率:0%
帮助的人:1211万
展开全部
第三题:

public class Point {
private int x,y;
public Point(int x,int y) {
this.x = x;
this.y = y;
}

public void showPoint() {
System.out.println("该点的坐标是:"+"("+this.x+","+this.y+")");
}

public void showDistance(Point pt) {
int a = this.x-pt.x;
int b = this.y-pt.y;
double distance = Math.sqrt(a*a+b*b);
System.out.println("两点的距离是:"+distance);
}

}

public class TestPoint {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Point pta = new Point(3,4);
Point ptb = new Point(5,6);
pta.showPoint();
ptb.showPoint();
pta.showDistance(ptb);
}

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式