Unite 香港佛牌討論區

設為首頁收藏本站

Unite 香港佛牌討論區

 取回密碼
 新會員登記

QQ登錄

只需一步,快速開始

Login

免註冊即享有會員功能

搜尋

Central Missouri Samsung Galaxy Note II N7100 Case

已有 80 次閱讀22-11-2013 05:31 | Central Missou, NHL Stars Sams

}

import java.awt.event.ComponentEvent;

System,Central Missouri Samsung Galaxy Note II N7100 Cases.out.println("OS supports translucency");

import javax.swing.SwingUtilities;

super("Translucent RectanguNBA Miami Heat iPhone 4s Caseslar Frame");

txtArea.setBackground(Color.CYAN);

*/

}

//Create graphics environment

System.out.println("OS supports translucency");

Let us check a sample code to implement the translucency feature. In this example we have created a rectangular translucent window on a text area. First we have disabled the decoration mode to get the effect of transparency. Then we have checked if the underlying operating system supports it or not,NHL Stars Samsung Galaxy S3 i9300 Cases. If supported the effect is visible on the frame window.

setShape(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));

}

public class TransRecFrame extends JFrame {

//Check if OS supports Translucency

public PixelTranslucency() {

setLayout(new GridBagLayout());

setSize(200, 300);

@Override

addComponentListener(new ComponentAdapter() {

How to Create Translucent and Shaped Windows in Java? · Full window translucency: In this approach full window is translucent. · Per pixel translucency: In this approach a part of the window is translucent · Shaped windows: Make different shaped windows like ovale, circle, rectangular etc.

GraphicsDevice,East Tennessee Samsung Galaxy Note II N7100 Cases.WindowTranslucency.TRANSLUCENT)) {

import java.awt.event.ComponentAdapter;

Back ground: In java UI, support for translucency and shaped window was a long time demand for Swing/AWT components. For native development access to these properties are available from long time back. But it was not accessible to core java components. In Java6 onward, support for translucency and shaped window is available. Even per pixel level translucency is also supports in Java7.

//Create label and set properties

//Set polygon properties

}

}

setUndecorated(true);

setVisible(true);

if (genv.getDefaultScreenDevice().isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)) {

Introduction: In some application, transparent window is a requirement to support its functionality. Now in Java, transparency can be implemented. A translucent window is created by altering its opacity by impNHL Devils iPhone 4s Caseslementing a method called setOpacity on a JFrame component. But we must understand that a translucent window is only possible if the underlying operating system supports it. And we also need to make sure that the window is not decorated. To make a window undecorated, you need to call setUndecorMemphis iPhone 4 Casesated (true) method. Some time it is also required to change the shape of a window UI. To implement it, we need to call setShape method within the componentResized method. It will recalculate the shape when the window is resized.

Features to support translucency and shape: In Java7 there are mainly three features available to support translucency and shape of a window.

if (genv.getDefaultScreenDevice().isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT)) {

import javax.swing.JFrame;

//Call for pixel setting

}

System.out.println("OS supports translucency");

import javax.swing.*;

public static void main(String[] args) {

[code]

import java.awt.GraphicsDevice;

import javax.swing.JTextArea;

setBackground(new Color(0, 0, 0, 0));

import java.awt.geom.GeneralPath;

private PixelPanel(int pixl) {

//Set lay out

gpath.append(polygon, true);

polygon.addPoint(0, 100);

Now we will discuss about another important feature supported by Java7.The shaped window supports all types of shapes whatever be the requirement of the user. This feature helps you to create any shape like circle, triangle, polygon or any possible complex shape. The setShape method of the window class is available for setting the property. But again we have to remember that full screen mode should not be allowed and the operating system supports translucency. The following example shows the usage of East Carolina iPhone 4 Casesshaped window.

add(Box.createHorizontalGlue());

getContentPane().setBackground(Color.cyan);

});

import java.awt.geom.Ellipse2D;

//Set box layout

GeneralPath gpath = new GeneralPath();

Before we use any of the above properties we need to test the support of under lying operating system. The test can be done by using method isWindowTranslucencySupported belonging to the java.awt.GraphicsDevice class. It takes the type of transparency as input and returns true/false to indicate the support.

//Set size

final JTextArea txtArea = new JTextArea(5, 50);

setVisible(true);

We have already seen how to make a complete window translucent in the previous example. Now we will discuss the second part of making a set of pixels translucent by using their background color. There are some limitations to implement this scenario. The window should not be full screen and the system must support pixel level translucency. The rest of the procedure is similar to the above example.

GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();

setLocationRelativeTo(null);

setVisible(true);

add(txtArea);

}

public static void main(String[] args) {

Listing3: The sample code showing the usage of shaped window.

PERPIXEL_TRANSLUCENT: This property supports different alpha values within the window itself. This is used to fade selected region of the window.

setSize(250, 250);

}

[code]

//Set other parameters

} private class PixelPanel extends JPanel {

JLabel newlabel = new JLabel("Java Shaped window");

super("Set shaped Window");

import java.awt.event.ActionEvent;

/**

[code]

We can also implement a combination of two features like translucency and shaped window. To implement this, call setOpacity method to your frame. The result window will display the combined effect. But we should remember the underlying operating system must support pixel level translucency and pixel level transparency.

}

//Set the values of the shape

[/code]

PERPIXEL_TRANSPARENT: This propertNorthern Arizona iPhone 4s Casesy supports different shapes of windows rather than traditional rectangle. If per pixel transparency is supported then different shapes like circle, triangle can be created.

super("Set pixel level translucency");

setSize(new Dimension(250, 250));

//Make the window 85% transparent

add(new PixelPanel(255 - i * 12));

GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();

import java.awt.GridBagLayout;

TRANSLUCENT: In this feature the window can have different colors but with the same level of opacity. So the alpha value is same for all the pixels. This effect is suitable for fade off a window and thWestern Michigan iPhone 4s Casesen gradually decreases and increases the alpha value.

//Check OS support for this property

polygon.addPoint(50, 0);

}

new PixelTranslucency();

public JavaShapedWindow() {

//Check if window supports translucency

}

import java.awt.*;

Ellipse2D.Double newCircle = new Ellipse2D.Double(0, 50, 1.0*100, 1.0*100);

setLocationRelativeTo(null);

[/code]

GraphicsEnvironment genv = GraphicsEnvironment

gpath.append(newCircle, true);

Conclusion: In this article we have covered some new features in java7.The translucency and shaped window features are really interesting and make java UI components more flexible. But at the same time we must rRadford iPhone 4s Casesemember that the underlying operating system should support all these properties. Otherwise the effect will not be visible. So in the application itself we check the OS support and then implement the effect. The latest feature of java allows the developers to create different types of effect on the UI side. As we all know that look and feel is an important aspect of any UI based application. So the developer is now equipped with tools to make the UI more pleasant and attractive.

setLocationRelativeTo(null);

new JavaShapedWindow();

[/code]

//Set content pane background color

public void componentResized(ComponentEvent e) {

for(int i = 0; i < 16; i++){

polygon.addPoint(100, 100);

super();

* Create a transparent rectangular frame with 85% transparency

//Set location

setBackground(new Color(0, 0, 255, pixl));

//Set background and other properties

In the following example we will see how pixel level translucency is set in a frame.

import java.awt.Color;

//Call to disable decoration

}

import java.awt.event.ActionListener;

.getLocalGraphicsEnviroBrown iPhone 4 Casesnment();

//Set general path properties

newlabel.setForeground(Color.white);

Listing2: Sample showing pixel level translucency support.

//Set the path

public static void main(String[] args) {

//Set size of the JFrame

getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));

Shaped Windows:

//Create a text area

}

setDefaultCloseOperation(EXIT_ON_CLOSE);

setUndecorated(true);

public class JavaShapedWindow extends JFrame {

public TransRecFrame() {

new TransRecFrame();

import javax.swing.*;

Per pixel translucency:

if (genv.getDefaultScreenDevice().isWindowTranslucencySupported(

Type of support for translucency and transparency: Java 7 supports the following three type of support.

import java.awt.*;

getContentPane().setLayout(new GridLayout(6, 6));

add(Box.createHorizontalGlue());

Polygon polygon = new Polygon();

//Set layout

}

setOpacity(0.85f);

Listing1: Sample showing TransluceColorado iPhone 4 Casesncy of a JFrame window

}

public class PixelTranslucency extends JFrame {

setShape(gpath);

//Set undecorated OFF to get an effect

import jaOhio iPhone 4 Casesva.awt.GraphicsEnvironment;

add(newlabel);

//Call setShape to resize the shape when widnow is resized

import java.awt.geom.Rectangle2D;


路過

雞蛋

鮮花

握手

雷人

評論 (0 個評論)

facelist doodle 塗鴉板

你需要登入後才可以評論 登入 | 新會員登記

QQ|小黑屋|手機版|網站地圖|聯絡我們|Unite Thai Amulet Forum (HK)    

GMT+8, 8-12-2016 00:37 , Processed in 0.061515 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2012 Comsenz Inc. | 正體中文: [數碼中文坊]

返回頂端