ZKX's LAB

java好看的图形界面 java图形界面设计

2020-10-19知识12

java图形界面设计 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class li53{public static void main(String args[]){ButtonDemo myButtonGUI=new ButtonDemo();myButtonGUI.setVisible(true);}}class ButtonDemo extends JFrame implements ActionListener{public static final int Width=250;public static final int Height=200;ButtonDemo(){setSize(Width,Height);setTitle(\"按钮事件样例\");Container conPane=getContentPane();conPane.setBackground(Color.blue);conPane.setLayout(new FlowLayout());JButton redBut=new JButton(\"red\");redBut.addActionListener(this);conPane.add(redBut);JButton greenBut=new JButton(\"green\");greenBut.addActionListener(this);conPane.add(greenBut);}public void actionPerformed(ActionEvent e){Container conPane=getContentPane();if(e.getActionCommand().equals(\"red\"))conPane.setBackground(Color.red);else if(e.getActionCommand().equals(\"green\"))conPane.setBackground(Color.green);}}我帮你改好了,在else if(e.getActionCommand().equals(\"green\"));这里多了个分号conPane。.

java好看的图形界面 java图形界面设计

java 的图形界面 不仅少了个r 还有两个问题:1、this.setVisible(true);this.setSize(600,400);这两句话要调换位置 不然屏幕上显示不了东西2、if(e.equals(\"确定\")){show.setText(\"恭喜你成功了\");}else if(e.equals(\"退出\")){System.exit(0);}把e 改为str

java好看的图形界面 java图形界面设计

java图形界面 /JFrame组建,Frame的扩展类,一个比较完整的窗口class Win extends JFrame/继承窗口类{public Win(){this.setSize(300,300);设置窗口显示的大小this.setVisible(true);设置窗口为显示的,参数为false则隐藏this.setDefaultColseOperation(JFrame.EXIT_ON_CLOSE);设置窗口默认的关闭方式为程序退出,参数为整数。}}JTextField,同为swing组建,是一个文本框,长度可以自己设置JTextField jt=new JTextFeld(10);创建一个文本框,文本框显示长度为10;将文本框在JFrame中显示,只需要一个JFrame的对象调用add()方法就可以了。Win win=new Win();窗口对象win.add(jt);添加组件取得文本框的输入,需要做事件的监听,可以是按钮,或者鼠标。只需要实现一下相应的接口,然后再相应的方法中完成代码KeyListener 按键监听KeyListener k=new KeyListener(){Overridepublic void keyTyped(KeyEvent e){}Overridepublic void keyReleased(KeyEvent e){键被松开的时候触发,调用下面的代码,参数携带键的信息*/}Overridepublic void keyPressed(KeyEvent e){键被按下的时候触发,调用下面的代码,参数携带键的信息*/if(e.getKeyCode()=KeyEvent。.

java好看的图形界面 java图形界面设计

java图形界面 简单的 按楼主意思做的。e79fa5e98193e59b9ee7ad9431333238653862。import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class WindowDemo extends Frame{public static void main(String[]a){new WindowDemo();}Label l=new Label();WindowDemo(){setLayout(new FlowLayout());Button bt1=new Button(\"确定\");Button bt=new Button(\"结束\");add(bt);add(bt1);add(l);bt1.addActionListener(new ButtonAct1());bt.addActionListener(new ButtonAct());pack();setVisible(true);setLocation(100,100);}class ButtonAct1 implements ActionListener{public void actionPerformed(ActionEvent arg){l.setText(\"1\");}}}class ButtonAct implements ActionListener{public void actionPerformed(ActionEvent arg0){System.exit(0);}}

JAVA图形界面设计 在awt/swing里绘制圆形的方法是g.drawOval(x,y,width,height);x,y代表外接正方形的左顶点坐标width和height相同是就是圆形.代表直径参考代码import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import javax.swing.JFrame;import javax.swing.JPanel;public class TestFrame extends JFrame {public TestFrame(){add(new CirclePanel());setSize(300,230);setLocationRelativeTo(null);setDefaultCloseOperation(EXIT_ON_CLOSE);}public static void main(String[]args){new TestFrame().setVisible(true);}绘制图形的面板class CirclePanel extends JPanel {int R=50;直径Overrideprotected void paintComponent(Graphics g){super.paintComponent(g);g.setColor(Color.BLUE);设置颜色为蓝色g.drawOval(80,30,R,R);圆形外接矩形的左顶点坐标是80,30;g.setColor(Color.BLACK);g.drawOval(120,30,R,R);g.setColor(Color.RED);g.drawOval(160,30,R,R);g.setColor(Color.YELLOW);g.drawOval(100,65,R,R);g.setColor(Color.GREEN);g.drawOval(140,65,R,R);g.setColor(Color.BLUE);设置颜色为蓝色g.setFont(new Font(\"宋体\",Font.BOLD。

感觉用java做出来的图形界面比较难看啊?有什么好的处理方法吗??请高手指点 try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(ClassNotFoundException e){TODO Auto-generated catch blocke.printStackTrace();} catch(InstantiationException e){TODO Auto-generated catch blocke.printStackTrace();} catch(IllegalAccessException e){TODO Auto-generated catch blocke.printStackTrace();} catch(UnsupportedLookAndFeelException e){TODO Auto-generated catch blocke.printStackTrace();}把上面的代码放到main的一开始,这样你的程序里面的按钮什么的就跟操作系统的那些按钮一致了,比默认的好看

用什么写Java图形界面比较好 虽然JAVA在图形用户界面方面不是很优秀,但做为现在流行的技术还是很受欢迎.用eclipse的VE插件支持直接拖动,方便快捷.当然NetBeans也是不错的选择.

java图形界面设计 /*因为是用long型来存储结果,所以如果你想求更大的阶乘的话换类型或者用其它的求高精度数值类*/import javax.swing.JFrame;import javax.swing.JPanel;import java.awt.BorderLayout;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class TestFact extends JFrame {private JTextField jtfNum;private JTextField jtfResult;public TestFact(){JPanel panel=new JPanel();getContentPane().add(panel,BorderLayout.CENTER);panel.setLayout(null);JLabel jlaInput=new JLabel(\"输入一个数:\");jlaInput.setBounds(12,94,70,28);panel.add(jlaInput);jtfNum=new JTextField();jtfNum.setBounds(121,94,114,30);panel.add(jtfNum);jtfNum.setColumns(10);JButton jbtCompute=new JButton(\"求阶乘\");jbtCompute.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){fact();}});jbtCompute.setBounds(67,151,117,24);panel.add(jbtCompute);jtfResult=new JTextField();。

#swing#图形界面

随机阅读

qrcode
访问手机版