首页 新闻 会员 周边

java窗体中,控件的外观是怎么绘制的?

0
悬赏园豆:10 [已关闭问题] 关闭于 2013-09-09 16:49

调用的是windows的绘制函数?还是直接调用驱动的绘制函数?比方说用java写的一个程序,其中有按钮,那么这个按钮是怎么绘制出来的?会调用windows的绘图函数么?

LiloT的主页 LiloT | 初学一级 | 园豆:6
提问于:2013-09-06 16:34
< >
分享
所有回答(4)
0

NO,调用java 的绘制函数、

Beyond-bit | 园豆:2885 (老鸟四级) | 2013-09-06 16:42

java绘制函数调用谁?

支持(0) 反对(0) LiloT | 园豆:6 (初学一级) | 2013-09-06 16:44

@LiloT: jdk已经封装好了,这个你不用关心,如果你需要重绘那你重写相关函数即可、‘

你要明白java跑在jvm里面,根本不用调用win.这个就是跨平台、如果按你说的,我要是移植到linux平台,那么调用win函数?你觉得会有win函数嘛?

支持(0) 反对(0) Beyond-bit | 园豆:2885 (老鸟四级) | 2013-09-06 16:48
0

内部实现通过类似opengl这样东西实现

andy1987 | 园豆:490 (菜鸟二级) | 2013-09-07 13:49

Java SWT不是在底层调用windowAPI吗?

支持(0) 反对(0) LiloT | 园豆:6 (初学一级) | 2013-09-09 15:40

(2) swing的图形界面自己绘制  这句话什么意思?

支持(0) 反对(0) LiloT | 园豆:6 (初学一级) | 2013-09-09 15:43
0
package test;

import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Round extends Frame implements ActionListener {
    TextField t1, t2, t3, t4;
    Button b1;
    Button btnExit;

    public Round() {
        setLayout(new FlowLayout());
        t1 = new TextField(20);
        t1.setBackground(Color.orange);
        t2 = new TextField(20);
        t2.setBackground(Color.orange);
        t3 = new TextField(20);
        t3.setBackground(Color.orange);
        t4 = new TextField(20);
        t4.setBackground(Color.orange);
        b1 = new Button("计算");
        btnExit = new Button("退出");
        add(new Label("输入圆的半径:"));
        add(t1);
        add(new Label("得出圆的直径:"));
        add(t2);
        add(new Label("得出圆的面积:"));
        add(t3);
        add(new Label("得出圆的周长:"));
        add(t4);
        add(b1);
        add(btnExit);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        b1.addActionListener(this);
        btnExit.addActionListener(this);
        setVisible(true);
        setBounds(200, 200, 200, 300);
        validate();
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b1) {
            double temp, r, a, c;
            temp = Float.parseFloat(t1.getText());
            r = 2 * temp;
            a = 3.14 * temp * temp;
            c = 2 * 3.14 * temp;
            t2.setText(String.valueOf(r));
            t3.setText(String.valueOf(a));
            t4.setText(String.valueOf(c));
        }
        if (e.getSource() == btnExit) {
            System.exit(0);
        }
    }

    public static void main(String args[]) {
        new Round();
    }
}
View Code

Java本身有内置的绘制函数可用。我觉得这个跟windows是没有关系的,因为java是跨平台的,不止能在Windows上运行,还能在比如Linux上运行。你可以看看这段代码,希望对你有帮助。

beyondchina | 园豆:680 (小虾三级) | 2013-09-09 14:59

Java SWT不是在底层调用windowAPI吗?

支持(0) 反对(0) LiloT | 园豆:6 (初学一级) | 2013-09-09 15:40
0
LiloT | 园豆:6 (初学一级) | 2013-09-09 16:49

力荐。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

支持(0) 反对(0) LiloT | 园豆:6 (初学一级) | 2013-09-09 16:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册