ZKX's LAB

java编程实现图形界面 java图形界面编程教程

2020-07-27知识9

java 图形界面编程问题 package Test1;import java.awt.*;import javax.swing.*;class Jie5 extends JFrame {JPanel contentPane,northPanel,southPanel;JTextField jtf1,jtf2;JButton jb[];public Jie5(){contentPane=new JPanel();northPanel=new JPanel();southPanel=new JPanel();jtf1=new JTextField();jtf2=new JTextField();jb=new JButton[10];this.setContentPane(contentPane);contentPane.setLayout(new BorderLayout(4,4));contentPane.add(northPanel,BorderLayout.NORTH);northPanel.setLayout(new GridLayout(3,3,4,4));for(int i=0;i;i+){jb[i]=new JButton(\"\"+(i+1));northPanel.add(jb[i]);}contentPane.add(southPanel,BorderLayout.SOUTH);southPanel.setLayout(new GridLayout(1,2,4,4));southPanel.add(jtf1);jtf1.setColumns(10);southPanel.add(jtf2);jtf2.setColumns(10);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setBounds(30,30,400,400);this.setTitle(\"hello\");}}public class Demo5 {param argspublic static void main(String[]args){try {TODO Auto-generated method stubUIManagersetLookAndFeel(。java图形用户界面编程 import java.applet.Applet;import java.awt.Graphics;public class MyApplet extends Applet {private static final long serialVersionUID=-3514248401804395713L;public MyApplet(){super();}public void init(){setSize(320,300);}public void paint(Graphics g){super.paint(g);int number=5;int r=50;int padd=30;int[][]arys=printCircle(number);for(int i=0;i;i+){for(int j=0;j;j+){g.drawString(\"\"+arys[i][j],padd+j*r,padd+i*r);System.out.print(arys[i][j]+\"\\t\");}System.out.println();}}private int[][]printCircle(int number){int[][]ary=new int[number][number];int rightLen;int downLen;int leftLen;int upLen;int rightRow=0;int rightCol=0;int leftRow=number-1;int leftCol=number-1;int downRow=1;int downCol=number-1;int upRow=number-2;int upCol=0;int digit=1;while(number>;0){rightLen=number;downLen=number-1;leftLen=number-1;upLen=number-2;for(int i=0,temp=rightCol;i;i+){ary[rightRow][temp+]=digit+;}for(int j=0,temp=downRow;j;j+){ary[temp+][downCol]=digit+;}for(int m=0,temp=leftCol-1;m;m+){ary。java里边图形界面编程 add(a1,BorderLayout.EAST);this;东\");JButton a2=new JButton(\".setSize(500修改成这样:import java.awt.*;import javax,400).NORTH);this.setDefaultCloseOperation(JFrame.add(a5,BorderLayout.CENTER);this,BorderLayout;中\");this;public class test2 extends JFrame{public static void main(String[]args){test2 a=new test2();}public test2(){JButton a1=new JButton(\".*;this.add(a4.add(a3,BorderLayout.SOUTH);this.setLocation(800,600);this;北\");JButton a5=new JButton(\"南\");JButton a4=new JButton(\"西\");JButton a3=new JButton(\".setTitle(\"边界布局BorderLayout\");this.EXIT_ON_CLOSE);this.swing.add(a2,BorderLayout.WEST);thisJava中怎么样进行图形界面编程? 用NetBeans做,可以直接拖放,不用自己布局,但是效率不怎么好

#event#图形界面

随机阅读

qrcode
访问手机版