123456吧 关注:3,172贴子:8,330
  • 8回复贴,共1
创建一个窗体,在其上显示出你的收件地址和邮政编码,如下图所示。要求,字体颜色为蓝色,字号大小30,字体类型宋体(p1/Information.java)。package p1;import java.awt.*;public class text1 {public static void main(String[lbk][rbk] args) {// TODO Auto-generated method stubFrame f=new Frame();f.setSize(500,200);MyPanel mp=new MyPanel();f.add(mp);f.setVisible(true);}}class MyPanel extends Panel{public void paint(Graphics g){g.setColor(Color.blue);g.setFont(new Font("宋体",0,30));g.drawString("地址:长春工业大学人文信息学院", 0, 50);g.drawString("计算机科学与工程学院", 0, 90);g.drawString("邮编:130122", 0, 130);}}


IP属地:吉林来自Android客户端1楼2024-07-02 15:13回复
    创建一个窗体,在其上显示如下图案。文字要求:颜色为绿色,字号大小20,字体类型隶书,外圆直径35,内圆直径为25 (p2/Circle.java)。
    package p2;
    import java.awt.*;public class text2 {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Frame f=new Frame();
    f.setSize(500,200);
    MyPanel mp=new MyPanel();
    f.add(mp);
    f.setVisible(true);
    }}
    class MyPanel extends Panel{
    public void paint(Graphics g){
    g.setColor(Color.green);
    g.setFont(new Font("隶书",0,20));
    g.drawString("两个同心圆", 50, 50);
    g.drawOval(230, 70, 35, 35);
    g.drawOval(235, 75, 25, 25);
    }
    }


    IP属地:吉林来自Android客户端2楼2024-07-02 15:14
    回复
      利用Java的多线程技术完成矩形框中蓝色实心小球的滚动问题。要求:在界面中有一个矩形框,实心小球起始位置在矩形框底边,向右滚动,到达矩形框右端停下,如下图(p3/Rect.java)。
      package p3;
      import java.awt.*;
      public class text3 {
      public static void main(String[] args) {
      Frame f=new Frame();
      f.setSize(300,400);
      MyPanel mp=new MyPanel();
      f.add(mp);
      Thread t=new Thread(mp);
      t.start();
      f.setVisible(true);
      }
      }
      class MyPanel extends Panel implements Runnable{
      int x=60,y=130;
      Boolean flag=true;
      public void paint(Graphics g){
      if(flag)
      g.drawString("正在努力加载", 30,30);
      else
      g.drawString("加载完成", 30, 30);
      g.setColor(Color.blue);
      g.fillOval(x, y, 30, 30);
      g.setColor(Color.black);
      g.drawRect(60,130, 160, 30);
      }
      @Override
      public void run() {
      // TODO Auto-generated method stub
      while(true){
      x++;
      if(x>=190){
      flag=false;
      break;
      }
      try{
      Thread.sleep(30);
      }catch(InterruptedException e){
      e.printStackTrace();
      }
      repaint();
      }
      }
      }


      IP属地:吉林来自Android客户端4楼2024-07-02 19:35
      回复
        利用Java的多线程技术完成进度条显示。要求:界面初始时,进度条为空,并显示正在努力加载,几秒钟后,进度条显示满格,并显示加载完成,如下图(p4/Progress_bar.java)。
        package p4;
        import java.awt.*;
        public class text4 {
        /**
        * @param args
        */
        public static void main(String[] args) {
        // TODO Auto-generated method stub
        Frame f=new Frame();
        f.setSize(300,400);
        MyPanel mp=new MyPanel();
        f.add(mp);
        Thread t=new Thread(mp);
        t.start();
        f.setVisible(true);
        }
        }
        class MyPanel extends Panel implements Runnable{
        Boolean flag=true;
        int x=0;
        public void paint(Graphics g){
        if(flag)
        g.drawString("正在努力加载", 30,30);
        else
        g.drawString("加载完成", 30, 30);
        g.setColor(Color.blue);
        g.drawOval(90, 90, 100, 100);
        g.fillArc(90, 90, 100, 100, 30, x);
        }
        @Override
        public void run() {
        // TODO Auto-generated method stub
        while(true){
        x-=5;
        if(x<=-360){
        flag=false;
        break;
        }
        try{
        Thread.sleep(80);
        }catch(InterruptedException e){
        e.printStackTrace();
        }
        repaint();
        }
        }
        }


        IP属地:吉林来自Android客户端5楼2024-07-02 19:37
        回复
          实现简易计算器,在前两个文本框输入数字,点击按钮实现相应运算并将结果显示在第三个文本框内,如下图。(p5/ Calculator.java)。
          package p5;
          import java.awt.*;
          import java.awt.event.*;
          import javax.swing.*;
          public class Calculator implements ActionListener{
          JFrame f=new JFrame();
          JLabel l1=new JLabel("第一个数:");
          JLabel l2=new JLabel("第二个数:");
          JLabel l3=new JLabel("运行结果:");
          JTextField t1=new JTextField();
          JTextField t2=new JTextField();
          JTextField t3=new JTextField();
          JPanel text=new JPanel();
          JButton multiple=new JButton("相加");
          JButton subtraction=new JButton("相减");
          JPanel button=new JPanel();
          public Calculator() {
          // TODO Auto-generated constructor stub
          f.setSize(300,200);
          f.setLocation(300, 300);
          text.setLayout(new GridLayout(3,2));
          text.add(l1);
          text.add(t1);
          text.add(l2);
          text.add(t2);
          text.add(l3);
          text.add(t3);
          button.setLayout(new FlowLayout());
          button.add(multiple);
          button.add(subtraction);
          f.setLayout(new BorderLayout());
          f.add(text,BorderLayout.CENTER);
          f.add(button,BorderLayout.SOUTH);
          multiple.addActionListener(this);
          subtraction.addActionListener(this);
          f.setVisible(true);
          }
          public static void main(String[] args) {
          // TODO Auto-generated method stub
          Calculator s=new Calculator();
          }
          @Override
          public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          int n=Integer.parseInt(t1.getText());
          int m=Integer.parseInt(t2.getText());
          if(e.getActionCommand().equals("相加")){
          t3.setText(""+(m+n));
          }
          if(e.getActionCommand().equals("相减")){
          t3.setText(""+(n-m));
          }
          }
          }


          IP属地:吉林来自Android客户端6楼2024-07-02 19:37
          回复
            1、
            package java_exam;
            import java.awt.*;
            public class a1 {
            public static void main(String[] args) {
            // TODO Auto-generated method stub
            Frame f=new Frame();
            f.setSize(500,400);
            Mypanel my=new Mypanel();
            f.add(my);
            f.setVisible(true);
            }
            }
            class Mypanel extends Panel{
            public void paint(Graphics g){
            g.setFont(new Font("宋体", 0, 30));
            g.setColor(Color.blue);
            g.drawString("地址:长春工业大学人文信息学院", 0, 50);
            g.drawString("计算机科学与工程", 0, 100);
            g.drawString("邮编:130122", 0, 150);
            }
            }
            ----------------------------------------------------------------------------------------------------
            2、
            package p2;
            import java.awt.*;
            public class a2 {
            public static void main(String[] args) {
            // TODO Auto-generated method stub
            Frame f=new Frame();
            f.setSize(400,300);
            //f.setLocation(500, 500);
            Mypanel md=new Mypanel();
            f.add(md);
            f.setVisible(true);
            }
            }
            class Mypanel extends Panel{
            public void paint(Graphics g){
            g.setFont(new Font("隶书", 0, 20));
            g.setColor(Color.green);
            g.drawString("两个同心圆", 100, 150);
            g.setColor(Color.green);
            g.drawOval(225,175 , 35, 35);
            g.drawOval(230,180 , 25, 25);
            }
            }
            ----------------------------------------------------------------------------------------------------
            3、
            package p3;
            import java.awt.*;
            public class a3 {
            /**
            * @param args
            */
            public static void main(String[] args) {
            // TODO Auto-generated method stub
            Frame f=new Frame();
            f.setSize(300,500);
            Mypanel my=new Mypanel();
            f.add(my);
            Thread t=new Thread(my);
            t.start();
            f.setVisible(true);
            }
            }
            class Mypanel extends Panel implements Runnable{
            //@Override
            int x=60;
            int y=130;
            Boolean flag=true;
            public void paint(Graphics g){
            if(flag==true)
            g.drawString("正在加载中", 30, 30);
            else
            g.drawString("加载完成", 30, 30);
            g.setColor(Color.blue);
            g.fillOval(x, y, 30, 30);
            g.setColor(Color.gray);
            g.drawRect(60,130 , 160, 30);
            }
            public void run() {
            // TODO Auto-generated method stub
            while(true){
            x+=3;
            if(x>190){
            flag=false;


            IP属地:吉林来自Android客户端7楼2024-07-02 19:39
            回复
              break;
              }
              try {
              Thread.sleep(10);
              } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              }
              repaint();
              }
              }
              }
              ----------------------------------------------------------------------------------------------------
              4、
              package p4;
              import java.awt.*;
              public class a4 {
              /**
              * @param args
              */
              public static void main(String[] args) {
              // TODO Auto-generated method stub
              Frame f=new Frame();
              f.setSize(300,300);
              Mypanel my=new Mypanel();
              f.add(my);
              Thread t=new Thread(my);
              t.start();
              f.setVisible(true);
              }
              }
              class Mypanel extends Panel implements Runnable{
              //@Override
              int x=0;
              boolean flag=true;
              public void paint(Graphics g){
              if(flag)
              g.drawString("正在加载中", 30, 30);
              else
              g.drawString("加载完成", 30, 30);
              g.setColor(Color.blue);
              g.drawOval(90, 90, 100, 100);
              g.fillArc(90, 90, 100, 100, 30,x );
              }
              public void run() {
              // TODO Auto-generated method stub
              while(true){
              x-=3;
              if(x<=-360){
              flag=false;
              break;
              }
              try {
              Thread.sleep(80);
              } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              }
              repaint();
              }
              }
              }


              IP属地:吉林来自Android客户端8楼2024-07-02 19:40
              回复
                5、
                package p5;
                import java.awt.*;
                import java.awt.event.ActionEvent;
                import java.awt.event.ActionListener;
                import javax.swing.*;
                public class Cal implements ActionListener{
                /**
                * @param args
                */
                JFrame jf=new JFrame();
                JLabel l1=new JLabel("第一个数");
                JLabel l2=new JLabel("第二个数");
                JLabel l3=new JLabel("运行结果");
                JTextField num1=new JTextField();
                JTextField num2=new JTextField();
                JTextField num3=new JTextField();
                JPanel text=new JPanel();
                JButton jia=new JButton("相加");
                JButton jian=new JButton("相减");
                JPanel button=new JPanel();
                public Cal(){
                jf.setSize(300,200);
                jf.setLocation(300,300);
                text.setLayout(new GridLayout(3, 2));
                text.add(l1);
                text.add(num1);
                text.add(l2);
                text.add(num2);
                text.add(l3);
                text.add(num3);
                button.add(jia);
                button.add(jian);
                jf.add(text,BorderLayout.CENTER);
                jf.add(button,BorderLayout.SOUTH);
                jia.addActionListener(this);
                jian.addActionListener(this);
                jf.setVisible(true);
                }
                public static void main(String[] args) {
                // TODO Auto-generated method stub
                Cal s=new Cal();
                }
                @Override
                public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                int m=Integer.parseInt(num1.getText());
                int n=Integer.parseInt(num2.getText());
                if(e.getActionCommand().equals("相加")){
                num3.setText(""+(m+n));
                }
                if(e.getActionCommand().equals("相减")){
                num3.setText(""+(m-n));
                }
                }
                }


                IP属地:吉林来自Android客户端9楼2024-07-02 19:41
                回复
                  package p6;
                  import java.awt.*;
                  import java.awt.event.*;
                  import java.sql.*;
                  import javax.swing.*;
                  public class Main_Page extends JFrame implements ActionListener{
                  JLabel l1=new JLabel("城市名称");
                  JLabel l2=new JLabel("人口数量(万)");
                  JLabel l3=new JLabel("城区面积(平方公里)");
                  JLabel l4=new JLabel("国内生产总值(亿元)");
                  JButton b1=new JButton("查询");
                  JButton b2=new JButton("取消");
                  JTextField jc=new JTextField();
                  JTextField jp=new JTextField();
                  JTextField ja=new JTextField();
                  JTextField jg=new JTextField();
                  JPanel p1=new JPanel();
                  JPanel p2=new JPanel();
                  Main_Page(){
                  this.setSize(360,260);
                  this.setLocation(300,300);
                  p1.setLayout(new GridLayout(4,2));
                  p1.add(l1);
                  p1.add(jc);
                  p1.add(l2);
                  p1.add(jp);
                  p1.add(l3);
                  p1.add(ja);
                  p1.add(l4);
                  p1.add(jg);
                  p2.add(b1);
                  p2.add(b2);
                  this.add(p1,BorderLayout.CENTER);
                  this.add(p2,BorderLayout.SOUTH);
                  b1.addActionListener(this);
                  b2.addActionListener(this);
                  }
                  public static void main(String[] args) {
                  Main_Page s=new Main_Page();
                  s.setVisible(true);
                  }
                  public void actionPerformed(ActionEvent e) {
                  if(e.getActionCommand().equals("查询")){
                  String city=jc.getText();
                  try {
                  Class.forName("org.gjt.mm.mysql.Driver");
                  Connection cn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/city","root","");
                  PreparedStatement ps=cn.prepareStatement("select * from city where cityname=?");
                  ps.setString(1, city);
                  ResultSet rs=ps.executeQuery();
                  if(rs.next()){
                  jp.setText(rs.getString(2));
                  ja.setText(rs.getString(3));
                  jg.setText(rs.getString(4));
                  }
                  rs.close();
                  ps.close();
                  cn.close();
                  } catch (ClassNotFoundException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                  }
                  catch (SQLException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                  }
                  }
                  if(e.getActionCommand().equals("取消")){
                  System.exit(0);
                  }
                  }
                  }


                  IP属地:吉林来自Android客户端10楼2024-07-02 19:42
                  回复