CS5303-Computer Science I(final review III)GUI

GUI

  • Fast Light Tool Kit(Full Tick)-FLTK :
    is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS®X.

A graphics library is a program library designed to aid in rendering computer graphics to a monitor


在这里插入图片描述

  • There are current three sets of Java APIs for graphics programming:
    AWT (Abstract Windowing Toolkit)
  • 提供了一套与本地图形界面进行交互的接口。
  • AWT 所提供的图形功能是各种通用型操作系统所提供的图形功能的交集
  • AWT 是依靠本地方法来实现其功能的,我们通常把AWT控件称为重量级控件
  • AWT 是基于本地方法的C/C++程序,其运行速度比较快;Swing是基于AWT 的Java程序,其运行速度比较慢

Class hierarchy of the AWT GUI classes
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Swing

  • 在AWT的基础上构建的一套新的图形界面系统,它提供了AWT 所能够提供的所有功能,并且用纯粹的Java代码对AWT 的功能进行了大幅度的扩充。
    Class hierarchy of the swing GUI classes(Two picture is the same)
    在这里插入图片描述
    The same as above

  • Swing is part of the so-called "Java Foundation Classes (JFC)

  • Swing component classes (in package javax.swing) begin with a prefix “J”, e.g., JButton, JTextField, JLabel, JPanel, JFrame, or JApplet.

在这里插入图片描述

JavaFX

  • JavaFX is a software platform for creating and delivering desktop applications, as well as rich Internet applications (RIAs) that can run across a wide variety of devices.
  • JavaFX is intended to replace Swing as the standard GUI library for Java SE, but both will be included for the foreseeable future.
  • java的UI库分为三代第一代是awt,第二代是swing,第三代就是javafx,互相之间是替代关系
    Sample code in Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class HelloJava2
{
	public static void main( String[] args ) {
		
		JFrame frame = new JFrame( "HelloJava2" );
		frame.add( new HelloComponent3("Hello, Java!") );
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		frame.setSize( 300, 300 );
		frame.setVisible( true );
	}
}

class HelloComponent3 extends JComponent
	implements MouseMotionListener, ActionListener
{
		String theMessage;
		int messageX = 125, messageY = 95; // Coordinates of the message
		JButton theButton;
		int colorIndex; // Current index into someColors
		static Color[] someColors = {
				
				Color.black, Color.red, Color.green, Color.blue, Color.magenta };
		
	public HelloComponent3( String message ) {
		
		theMessage = message;
		theButton = new JButton("Change Color");
		setLayout( new FlowLayout() );
		add( theButton );
		theButton.addActionListener( this );
		addMouseMotionListener( this );
	}
	
	public void paintComponent( Graphics g ) {
		
		g.drawString( theMessage, messageX, messageY );
		
	}
	
	public void mouseDragged( MouseEvent e ) {
		
		messageX = e.getX();
		messageY = e.getY();
		repaint();
		
	}
	public void mouseMoved( MouseEvent e ) {}
	public void actionPerformed( ActionEvent e ) {
		
		// Did somebody push our button?
		if (e.getSource() == theButton)
		changeColor();
		
	}
	synchronized private void changeColor() {
		// Change the index to the next color, awkwardly.
		if (++colorIndex == someColors.length)
			colorIndex = 0;
		setForeground( currentColor() ); // Use the new color.
		repaint();
	}
	synchronized private Color currentColor() {
	
		return someColors[colorIndex];
	}
}

Just slides

Invalidation

是一个很有用的机制,可将组件更改延迟到稍后屏幕更新时进行处理,从而消除了重复的工作。

例如,要更改宽度和高度,如果在更改宽度后立即更新组件,然后在设置新高度后再次更新组件,就有些浪费。更改两个属性后再使用新的大小一次性呈示组件,效率会更高。

很少调用 Invalidation 方法。通常,在组件上设置属性会自动调用合适的 invalidation 方法。

OnPaint

The OnPaint method is called whenever the plug-in window should paint itself


baker’s slides is very hard to conclude.


在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值