Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.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 使用swing制作3D按钮_Java_Swing - Fatal编程技术网

Java 使用swing制作3D按钮

Java 使用swing制作3D按钮,java,swing,Java,Swing,我有以下代码,其中包含两个按钮: 我的要求是改变按钮的字体和颜色,给他们一个3D的外观 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.Border; import javax.swing.table.DefaultTableModel; import java.beans.*; import java.io.FileInputStream; import ja

我有以下代码,其中包含两个按钮: 我的要求是改变按钮的字体和颜色,给他们一个3D的外观

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;
import java.beans.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.Random;

@SuppressWarnings("serial")
public class UserGui extends JPanel implements ActionListener, PropertyChangeListener {
    static UserGui currentObj; 
    private JProgressBar progressBar;
    private JButton generateButton;
    private JButton exceptionButton;
    private JTextArea taskOutput;
    private Task task;
    DefaultTableModel model;
    JTable table;
    JScrollPane spane;
    int currentRow=-1;

    class Task extends SwingWorker<Void, Void> {
        /*
         * Main task. Executed in background thread.
         */
        @Override
        public Void doInBackground() {
            Random random = new Random();
            int progress = 0;
            //Initialize progress property.
            setProgress(0);
            while (progress < 100) {
                //Sleep for up to one second.
                try {
                    Thread.sleep(random.nextInt(1000));
                } catch (InterruptedException ignore) {}
                //Make random progress.
                progress += random.nextInt(10);
                setProgress(Math.min(progress, 100));
            }
            return null;
        }
        /*
         * Executed in event dispatching thread
         */
        @Override
        public void done() {
            Toolkit.getDefaultToolkit().beep();
            generateButton.setEnabled(true);
            setCursor(null); //turn off the wait cursor
            taskOutput.append("Done!\n");
        }
    }

    public UserGui() {
        // super(null);

        JLabel headerLabel = new JLabel("", JLabel.LEADING); 
        headerLabel.setText("TEST APPLICATION");  
        headerLabel.setFont(new Font("Calibri",Font.ITALIC,25));

        //Create the demo's UI.
        generateButton = new JButton("button1");
        generateButton.setActionCommand("generate");
        generateButton.addActionListener(this);


        exceptionButton = new JButton("button2");
        exceptionButton.setActionCommand("exception");
        exceptionButton.addActionListener(this);
        // exceptionButton.setBounds(50, 300, 150, 30);

        progressBar = new JProgressBar(0, 100);
        // progressBar.setBounds(0, 0, HEIGHT, WIDTH);
        progressBar.setValue(0);
        progressBar.setStringPainted(true);
        //progressBar.setBounds(x, y, width, height)

        taskOutput = new JTextArea(5, 20);
        taskOutput.setMargin(new Insets(5,5,5,5));
        taskOutput.setEditable(false);

        //LABEL PANEL
        JPanel labelpanel = new JPanel();
        //labelpanel.setBounds(0, 0, WIDTH, 80);
        labelpanel.setLayout(null);      
        ImageIcon icon = new ImageIcon("logo.jpg","hiii");
        JLabel imgl=new JLabel(icon);
        labelpanel.add(imgl);
        labelpanel.add(headerLabel);
        imgl.setBounds(10,10, 150, 70);
        headerLabel.setBounds(200, 0, 400, 70);
        //labelpanel.setBorder((BorderFactory.createEmptyBorder(200, 200, 200, 200)));

        //BUTTON PANEL
        JPanel buttonpanal=new JPanel();

        buttonpanal.setLayout(null);
        buttonpanal.add(generateButton);
        buttonpanal.add(exceptionButton);
        Dimension d1=generateButton.getPreferredSize();
        System.out.println(d1);
        generateButton.setBounds(10,10,133,26);
        exceptionButton.setBounds(10,66,133,26);


        //SCROLL PANE
        model=new DefaultTableModel();
        table=new JTable(model);
        model.addColumn("ID");
        model.addColumn("IEC");
        model.addColumn("IFSC");
        model.addColumn("SHB_NO");
        model.addColumn("STATUS");

        table.setFillsViewportHeight(true);
        spane=new JScrollPane(table);

        //PROGERSS BAR
        JPanel progbar=new JPanel();
        progbar.add(progressBar);
        //  progressBar.setBounds(x, y, width, height)

        //ADD PANELS TO JFRAME
        add(labelpanel);
        labelpanel.setBounds(0,0,600,100);

        add(buttonpanal);
        buttonpanal.setBounds(0,100,160,300);

        add(spane);
        spane.setBounds(160,110, 500, 300);


        progbar.setBackground(new Color(153,153,255));
        labelpanel.setBackground(new Color(153,153,255));
        buttonpanal.setBackground(new Color(153,153,255));
        headerLabel.setBackground(new Color(153,153,255));
        progressBar.setBackground(new Color(153,153,255));
    }

    public void adddata(Object[] data){
        if(model!=null){

            model.addRow(data);
            currentRow++;
        }
    }

    public void updateStatus(String status){
        if(table!=null){
            System.out.println("...currentRow:"+currentRow);
            table.setValueAt(status, currentRow, 4);

            System.out.println("out of......");
        }
    }

    /**
    * Invoked when the user presses the start button.
    */
    public void actionPerformed(ActionEvent evt) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        currentObj=this;      
        System.out.println("in action......");
        Properties prop = new Properties();
        InputStream input = null;

        setCursor(Cursor.getDefaultCursor());
    }

    /**
    * Invoked when task's progress property changes.
    */
    public void propertyChange(PropertyChangeEvent evt) {
        if ("progress" == evt.getPropertyName()) {
            int progress = (Integer) evt.getNewValue();
            progressBar.setValue(progress);
            taskOutput.append(String.format(
                    "Completed %d%% of task.\n", task.getProgress()));
        } 
    }

    /**
    * Create the GUI and show it. As with all GUI code, this must run
    * on the event-dispatching thread.
    */
    public static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("ProgressBarDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        JComponent newContentPane = new UserGui();
        newContentPane.setOpaque(true); //content panes must be opaque
        newContentPane.setLayout(null);
        frame.setContentPane(newContentPane);
        frame.setSize(700, 500);
        //frame.setLayout(null);
        //Display the window.
        //frame.pack();
        frame.setVisible(true);
        frame.setAlwaysOnTop(true);
        frame.setBackground(new Color(153,153,255));
        newContentPane.setBackground(new Color(153,153,255));
        }
        public static void main(String[] args)throws Exception {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
import java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
导入javax.swing.border.border;
导入javax.swing.table.DefaultTableModel;
导入java.beans。*;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.IOException;
导入java.io.InputStream;
导入java.sql.ResultSet;
导入java.sql.SQLException;
导入java.util.Properties;
导入java.util.Random;
@抑制警告(“串行”)
公共类UserGui扩展JPanel实现ActionListener、PropertyChangeListener{
静态用户界面currentObj;
私人JProgressBar progressBar;
私有JButton generateButton;
私有JButton例外按钮;
专用JTextArea任务输出;
私人任务;
默认表格模型;
JTable表;
Jscollpane spane;
int currentRow=-1;
类任务扩展SwingWorker{
/*
*主任务。在后台线程中执行。
*/
@凌驾
公共无效doInBackground(){
随机=新随机();
int progress=0;
//初始化进度属性。
setProgress(0);
而(进度<100){
//最多睡一秒钟。
试一试{
Thread.sleep(random.nextInt(1000));
}捕获(中断异常忽略){}
//随机取得进展。
进度+=随机。下一步(10);
setProgress(Math.min(progress,100));
}
返回null;
}
/*
*在事件调度线程中执行
*/
@凌驾
公众假期结束(){
getDefaultToolkit().beep();
generateButton.setEnabled(真);
setCursor(null);//关闭等待光标
taskOutput.append(“完成!\n”);
}
}
公共用户界面(){
//超级(空);
JLabel headerLabel=新JLabel(“,JLabel.LEADING”);
headerLabel.setText(“测试应用”);
headerLabel.setFont(新字体(“Calibri”,字体斜体,25));
//创建演示的UI。
generateButton=新按钮(“按钮1”);
setActionCommand(“生成”);
generateButton.addActionListener(此);
例外按钮=新按钮(“按钮2”);
setActionCommand(“异常”);
exceptionButton.addActionListener(此);
//例外按钮。立根(50、300、150、30);
progressBar=新的JProgressBar(01100);
//progressBar.setBounds(0,0,高度,宽度);
progressBar.setValue(0);
progressBar.SetStringPaint(真);
//progressBar.setBounds(x、y、宽度、高度)
taskOutput=新的JTextArea(5,20);
taskOutput.setMargin(新插图(5,5,5,5));
taskOutput.setEditable(false);
//标签面板
JPanel labelpanel=新的JPanel();
//标签面板立根(0,0,宽度,80);
labelpanel.setLayout(空);
ImageIcon图标=新的ImageIcon(“logo.jpg”、“hiii”);
JLabel imgl=新的JLabel(图标);
labelpanel.add(imgl);
标签面板。添加(标题标签);
imgl.立根(10,10,150,70);
头部标签立根(200,0,400,70);
//labelpanel.setBorder((BorderFactory.createEmptyByOrder(200200200200200));
//按钮面板
JPanel buttonpanal=新的JPanel();
buttonpanal.setLayout(空);
buttonpanal.add(生成按钮);
buttonpanal.add(例外按钮);
维度d1=generateButton.getPreferredSize();
系统输出打印项次(d1);
生成按钮.立根(10,10133,26);
例外按钮.立根(10,66133,26);
//滚动窗格
模型=新的DefaultTableModel();
表=新JTable(型号);
model.addColumn(“ID”);
型号。添加柱(“IEC”);
模型。添加列(“IFSC”);
型号.添加柱(“SHB_编号”);
model.addColumn(“状态”);
表.setFillsViewPerthweight(真);
spane=新的JScrollPane(表);
//进度条
JPanel progbar=新的JPanel();
progbar.add(progressBar);
//progressBar.setBounds(x、y、宽度、高度)
//将面板添加到JFRAME
添加(标签面板);
标签面板立根(0,0600100);
添加(按钮名称);
按钮背面立根(0100160300);
添加(spane);
span.立根(160110500300);
progbar.setBackground(新颜色(153255));
labelpanel.setBackground(新颜色(153255));
按钮背面退根(新颜色(153255));
标题标签。挫折背景(新颜色(153255));
progressBar.setBackground(新颜色(153255));
}
公共void adddata(对象[]数据){
如果(型号!=null){
model.addRow(数据);
currentRow++;
}
}
公共void updateStatus(字符串状态){
如果(表!=null){
System.out.println(“…currentRow:+currentRow”);
表.setValueAt(状态,当前行,4);
System.out.println(“out of…”);
}
}
/**
*当用户按下开始按钮时调用。
*/
已执行的公共无效操作(操作事件evt){
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_Cursor));
currentObj=这个;
System.out.println(“正在运行……”);
Properties prop=新属性();
InputStream输入=null;
setCursor(Cursor.getDefaultCursor());
}
/**
*当任务的进度属性更改时调用。
*/
公共作废属性更改(属性更改事件evt){
if(“progress”==evt.getPropertyName()){
int progress=(整数)evt.getNewValue();
progressBar.setValue(进度);
taskOutput.append(