Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中创建具有圆边的框架..我已经创建了圆边按钮_Java_Swing - Fatal编程技术网

如何在Java中创建具有圆边的框架..我已经创建了圆边按钮

如何在Java中创建具有圆边的框架..我已经创建了圆边按钮,java,swing,Java,Swing,我认为可以使用AWTUtilities.setWindowShape。看看这篇文章: 但是,awutilities尚未公开,因为它在com.sun.awt包中,所以您不应该使用它。我相信它将在Java 7中发布。这些圆角是什么?我们是否担心用户会在尖角处割伤自己?“对我来说,这似乎是在浪费屏幕面积。”安德鲁·汤普森笑着说。。并没有用户不能切割自己,但若您正在开发一个项目,GUI的外观也可能意味着很多:-) import java.awt.*; import javax.swing.*; impo

我认为可以使用
AWTUtilities.setWindowShape
。看看这篇文章:


但是,
awutilities
尚未公开,因为它在
com.sun.awt
包中,所以您不应该使用它。我相信它将在Java 7中发布。

这些圆角是什么?我们是否担心用户会在尖角处割伤自己?“对我来说,这似乎是在浪费屏幕面积。”安德鲁·汤普森笑着说。。并没有用户不能切割自己,但若您正在开发一个项目,GUI的外观也可能意味着很多:-)
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.border.*;

public class ChangeButtonShape {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(null);
JLabel l=new JLabel("Name");
final JTextField text=new JTextField(20);
JButton button = new JButton("Go");
//button.setBackground(Color.lightGray);
l.setBounds(10,10,100,20);
text.setBounds(100,10,180,20);
button.setBounds(10,40,50,20);
button.setBorder(new RoundedBorder(10));
frame.add(l);
frame.add(text);
frame.add(button);

button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
String st=text.getText();
JOptionPane.showMessageDialog(null,"Hello "+st);
    }
});
frame.setSize(300,150);
frame.setVisible(true);
}
}
class RoundedBorder implements Border {
        int radius;
        RoundedBorder(int radius) {
            this.radius = radius;
        }
        public Insets getBorderInsets(Component c) {
            return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
        }
        public boolean isBorderOpaque() {
            return true;
        }
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            g.drawRoundRect(x,y,width-1,height-1,radius,radius);
        }
    }