<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • java展示圖文的代碼 java圖形界面代碼

            JAVA的圖形用戶界面代碼

            package hao;

            站在用戶的角度思考問題,與客戶深入溝通,找到臺江網站設計與臺江網站推廣的解決方案,憑借多年的經驗,讓設計與互聯(lián)網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:做網站、成都網站制作、企業(yè)官網、英文網站、手機端網站、網站推廣、域名注冊、網絡空間、企業(yè)郵箱。業(yè)務覆蓋臺江地區(qū)。

            import java.awt.BorderLayout;

            import java.awt.Color;

            import java.awt.Dimension;

            import java.awt.GridLayout;

            import java.io.File;

            import javax.swing.BorderFactory;

            import javax.swing.Box;

            import javax.swing.ImageIcon;

            import javax.swing.JButton;

            import javax.swing.JComboBox;

            import javax.swing.JLabel;

            import javax.swing.JPanel;

            import javax.swing.JScrollPane;

            import javax.swing.JTextArea;

            import javax.swing.JTextPane;

            import javax.swing.text.BadLocationException;

            import javax.swing.text.SimpleAttributeSet;

            import javax.swing.text.StyleConstants;

            import javax.swing.text.StyledDocument;

            public class ChatPanel extends JPanel {

            private static final long serialVersionUID = 1L;

            JButton send,record,saveRecord,image;

            JTextArea inputArea;

            JTextPane text;//注意用法****************************************************************************

            JComboBox fontName = null, fontSize = null, fontStyle = null, fontColor = null,fontBackColor = null;

            public StyledDocument doc = null; JScrollPane scrollPane;JPanel textChat;

            JButton music;

            public ChatPanel() {

            setLayout(new BorderLayout());

            text = new JTextPane();

            text.setEditable(false);

            doc = text.getStyledDocument();//跟蹤文本和圖片寫到該區(qū)域的位置*************************************

            scrollPane = new JScrollPane(text);

            //注意下面對JComboBox的巧用***********************************************************************

            String[] str_name = { "宋體", "黑體", "Dialog", "Gulim" };

            String[] str_Size = { "12", "14", "18", "22", "30", "40" };

            String[] str_Style = { "常規(guī)", "斜體", "粗體", "粗斜體" };

            String[] str_Color = { "黑色", "紅色", "藍色", "黃色", "綠色" };

            String[] str_BackColor = { "無色", "灰色", "淡紅", "淡藍", "淡黃", "淡綠" };

            fontName = new JComboBox(str_name);

            fontSize = new JComboBox(str_Size);

            fontStyle = new JComboBox(str_Style);

            fontColor = new JComboBox(str_Color);

            fontBackColor = new JComboBox(str_BackColor);

            fontName.setBackground(new Color(255,153,255));

            fontSize.setBackground(new Color(255,153,255));

            fontStyle.setBackground(new Color(255,153,255));

            fontColor.setBackground(new Color(255,153,255));

            fontBackColor.setBackground(new Color(255,153,255));

            Box box = Box.createVerticalBox();//創(chuàng)建一個可以容納多個Box組件的Box*******************************

            Box box_1 = Box.createHorizontalBox();

            Box box_2 = Box.createHorizontalBox();

            Box box_4 = Box.createHorizontalBox();

            box.add(box_1);

            box.add(box_2);

            box.add(box_4);

            JLabel b1= new JLabel("字體~~"), b2 = new JLabel("樣式~~"),b3 = new JLabel("字號~~"),b4 = new JLabel("顏色~~"),b5 = new JLabel("背景~~");

            b1.setBackground(new Color(255,153,255));

            b2.setBackground(new Color(255,153,255));

            b3.setBackground(new Color(255,153,255));

            b4.setBackground(new Color(255,153,255));

            b5.setBackground(new Color(255,153,255));

            box_1.add(b1);

            box_1.add(fontName);

            box_1.add(Box.createHorizontalStrut(8));

            box_1.add(b2);

            box_1.add(fontStyle);

            box_1.add(Box.createHorizontalStrut(8));

            box_1.add(b3);

            box_1.add(fontSize);

            box_2.add(Box.createHorizontalStrut(8));

            box_2.add(b4);

            box_2.add(fontColor);

            box_2.add(Box.createHorizontalStrut(8));

            box_4.add(b5);

            box_4.add(fontBackColor);

            textChat = new JPanel();

            textChat.setLayout(new BorderLayout());

            textChat.setBackground(new Color(255,153,255));

            inputArea = new JTextArea(3, 20);

            inputArea.setLineWrap(true); //設置文本區(qū)的換行策略。88888*********************************

            send = new JButton("發(fā)送");

            record=new JButton("顯示記錄");

            saveRecord=new JButton("儲存記錄");

            image=new JButton("表情");

            send.setBackground(new Color(255,153,255));

            record.setBackground(new Color(255,153,255));

            saveRecord.setBackground(new Color(255,153,255));

            image.setBackground(new Color(255,153,255));

            Box box_3 = Box.createHorizontalBox();

            box_3.add(send); box_3.add(Box.createHorizontalStrut(8));//設置按鈕間距*************************888

            box_3.add(record); box_3.add(Box.createHorizontalStrut(8)); //設置按鈕間距*************************888

            box_3.add(saveRecord); box_3.add(Box.createHorizontalStrut(8));//設置按鈕間距*************************888

            box_3.add(image);

            box.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));//設置Box的邊框線********************

            box_3.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));

            textChat.add(box,BorderLayout.NORTH);

            textChat.add(inputArea,BorderLayout.CENTER);

            textChat.add(box_3, BorderLayout.SOUTH);

            inputArea.requestFocus(true);

            inputArea.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5));//設置輸入窗口邊框線*******************

            text.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),8));//設置輸入窗口邊框線*******************

            JPanel audioPanel = new JPanel();//最上面的邊框************************************************************************

            audioPanel.setBackground(new Color(255,153,255));

            audioPanel.setLayout(new GridLayout(1,1));

            music = new JButton("想聽就聽");

            music.setPreferredSize(new Dimension(320,50));

            music.setBorder(BorderFactory.createLineBorder(Color.BLACK,10));//設置輸入窗口邊框線*******************

            audioPanel.add(music);

            add(audioPanel, BorderLayout.NORTH);

            add(scrollPane,BorderLayout.CENTER);

            add(textChat, BorderLayout.SOUTH);

            }

            void insertIcon(ImageIcon image) {

            text.setCaretPosition(doc.getLength());

            text.insertIcon(image);

            insert(new MessageStyle());//?????????????????????????????????????????????????????????????????????????????/

            }

            public void insert(MessageStyle attrib) {

            try {

            doc.insertString(doc.getLength(), attrib.getText() + "\n", attrib.getAttrSet());//寫完后接著換行************

            } catch (BadLocationException e) {

            e.printStackTrace();

            }

            }

            public MessageStyle getMessageStyle(String line) {

            MessageStyle att = new MessageStyle();

            att.setText(line);

            att.setName((String) fontName.getSelectedItem());

            att.setSize(Integer.parseInt((String) fontSize.getSelectedItem()));

            String temp_style = (String) fontStyle.getSelectedItem();

            if (temp_style.equals("常規(guī)")) {

            att.setStyle(MessageStyle.GENERAL);

            }

            else if (temp_style.equals("粗體")) {

            att.setStyle(MessageStyle.BOLD);

            }

            else if (temp_style.equals("斜體")) {

            att.setStyle(MessageStyle.ITALIC);

            }

            else if (temp_style.equals("粗斜體")) {

            att.setStyle(MessageStyle.BOLD_ITALIC);

            }

            String temp_color = (String) fontColor.getSelectedItem();

            if (temp_color.equals("黑色")) {

            att.setColor(new Color(0, 0, 0));

            }

            else if (temp_color.equals("紅色")) {

            att.setColor(new Color(255, 0, 0));

            }

            else if (temp_color.equals("藍色")) {

            att.setColor(new Color(0, 0, 255));

            }

            else if (temp_color.equals("黃色")) {

            att.setColor(new Color(255, 255, 0));

            }

            else if (temp_color.equals("綠色")) {

            att.setColor(new Color(0, 255, 0));

            }

            String temp_backColor = (String) fontBackColor.getSelectedItem();

            if (!temp_backColor.equals("無色")) {

            if (temp_backColor.equals("灰色")) {

            att.setBackColor(new Color(200, 200, 200));

            }

            else if (temp_backColor.equals("淡紅")) {

            att.setBackColor(new Color(255, 200, 200));

            }

            else if (temp_backColor.equals("淡藍")) {

            att.setBackColor(new Color(200, 200, 255));

            }

            else if (temp_backColor.equals("淡黃")) {

            att.setBackColor(new Color(255, 255, 200));

            }

            else if (temp_backColor.equals("淡綠")) {

            att.setBackColor(new Color(200, 255, 200));

            }

            }

            return att;

            }

            }

            怎么用java代碼模擬一張圖片

            用java代碼模擬一張圖片可以這樣操作:1.創(chuàng)建BufferedImage類

            2.根據(jù)BufferedImage類得到一個Graphics2D對象

            3.根據(jù)Graphics2D對象進行邏輯操作

            4.處理繪圖

            5.將繪制好的圖片寫入到圖片

            求一個簡單的java代碼:(圖形界面)

            import java.awt.Color;

            import java.awt.Dimension;

            import java.awt.Toolkit;

            import java.awt.event.ActionEvent;

            import java.awt.event.ActionListener;

            import javax.swing.JButton;

            import javax.swing.JDialog;

            import javax.swing.JLabel;

            import javax.swing.JOptionPane;

            import javax.swing.JPasswordField;

            import javax.swing.JTextField;

            public class vv extends JDialog {

            private static final long serialVersionUID = 1L;

            private JLabel l_Id = new JLabel("登陸賬戶", JLabel.CENTER);

            private JLabel l_pw = new JLabel("登陸密碼", JLabel.CENTER);

            private JTextField t_Id = new JTextField(10);

            private JPasswordField t_pw = new JPasswordField(10);

            private JButton btnLogin;

            private JButton btnClose;

            public vv() {

            super();

            setResizable(false);

            getContentPane().setBackground(new Color(225, 225, 225));

            getContentPane().setLayout(null);

            initialize();

            }

            protected void initialize() {

            setTitle("系統(tǒng)登錄");

            l_Id.setBounds(48, 43, 53, 25);

            t_Id.setBounds(110, 43, 150, 25);

            l_pw.setBounds(48, 93, 53, 25);

            t_pw.setBounds(110, 93, 150, 25);

            getContentPane().add(l_Id);

            getContentPane().add(l_pw);

            getContentPane().add(t_Id);

            getContentPane().add(t_pw);

            btnLogin = new JButton();

            btnLogin.setText("登 錄");

            btnLogin.setBounds(70, 142, 85, 28);

            btnLogin.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

            addBtnLoginActionListener();

            }

            });

            getContentPane().add(btnLogin);

            btnClose = new JButton();

            btnClose.setText("關 閉");

            btnClose.setBounds(175, 142, 85, 28);

            btnClose.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

            dispose();

            System.exit(-1);

            }

            });

            getContentPane().add(btnClose);

            }

            private void addBtnLoginActionListener() {

            String user = t_Id.getText();

            String password = new String(t_pw.getPassword());

            if (user.equals("")) {

            JOptionPane.showMessageDialog(this, "帳號不可為空", "Caution",

            JOptionPane.WARNING_MESSAGE);

            return;

            }

            if (password.equals("")) {

            JOptionPane.showMessageDialog(this, "密碼不可為空", "Caution",

            JOptionPane.WARNING_MESSAGE);

            return;

            }

            String sql = "select * FROM login WHERE id = '" + user + "' and pw = '"

            + password + "'";

            boolean success = false;

            // TODO:數(shù)據(jù)校驗 success = executeQuery(sql);

            if (success) {

            // TODO: 如果數(shù)據(jù)校驗成功 顯示主界面 并關閉登錄界面

            JOptionPane.showMessageDialog(this, "成功登錄", "提示",

            JOptionPane.INFORMATION_MESSAGE);

            this.dispose();

            } else {

            JOptionPane.showMessageDialog(this, "帳號或密碼錯誤!", "警告",

            JOptionPane.WARNING_MESSAGE);

            t_pw.requestFocus(); // 密碼框選中

            }

            }

            public Dimension getPreferredSize() {

            return new Dimension(320, 170);

            }

            public void show() {

            Toolkit tk = Toolkit.getDefaultToolkit();

            Dimension screen = tk.getScreenSize();

            Dimension d = getSize();

            this.setLocation((screen.width - d.width) / 2,

            (screen.height - d.height) / 2);

            // 輸入密碼后回車相當于點擊了登錄按鈕

            getRootPane().setDefaultButton(btnLogin);

            t_pw.requestFocus();

            setDefaultCloseOperation(DISPOSE_ON_CLOSE);

            setSize(300, 220);

            super.show();

            }

            public static void main(String[] args) {

            vv loginFrame = new vv();

            loginFrame.setVisible(true);

            }

            }

            希望對你有幫助

            文章名稱:java展示圖文的代碼 java圖形界面代碼
            分享地址:http://www.jbt999.com/article18/hppegp.html

            成都網站建設公司_創(chuàng)新互聯(lián),為您提供云服務器、靜態(tài)網站、響應式網站網站建設、定制開發(fā)定制網站

            廣告

            聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

            搜索引擎優(yōu)化

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 美女骚逼| 国产毛片在线视频 | 免费性爱视频在线观看 | 波多野结衣视频网址 | 国产亲子乱伦 |