画空心矩形的代码是什么?要java的。
3个回答
展开全部
以下是代码,可以参考一下,希望对您有帮助。
============================================
public class PrintStars {
private static final int LENGTH=10;
private static final int WIDTH=20;
public static void main(String[] args) {
for (int i = 0; i < LENGTH; i++) {
if(i==0||i==LENGTH-1){
for (int j = 0; j < WIDTH; j++) {
System.out.print("* ");
}
}else {
for (int j = 0; j < WIDTH; j++) {
if(j==0||j==WIDTH-1){
System.out.print("* ");
}else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
============================================
public class PrintStars {
private static final int LENGTH=10;
private static final int WIDTH=20;
public static void main(String[] args) {
for (int i = 0; i < LENGTH; i++) {
if(i==0||i==LENGTH-1){
for (int j = 0; j < WIDTH; j++) {
System.out.print("* ");
}
}else {
for (int j = 0; j < WIDTH; j++) {
if(j==0||j==WIDTH-1){
System.out.print("* ");
}else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
展开全部
//图形界面的,献上
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class RectangleFrame extends JFrame {
RectangleFrame() {
//增加面板
JPanel jp = new JPanel();
jp.setBounds(0, 0, 800, 600);
this.add(jp);
JButton bt = new JButton("画出矩形");
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Graphics g = getGraphics();
g.setColor(Color.BLACK);
g.drawRect(50, 50, 100, 200);
}
});
jp.add(bt);
// 设置窗体的位置和大小
this.setBounds(200, 50, 800, 600);
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
new RectangleFrame().setVisible(true);
}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class RectangleFrame extends JFrame {
RectangleFrame() {
//增加面板
JPanel jp = new JPanel();
jp.setBounds(0, 0, 800, 600);
this.add(jp);
JButton bt = new JButton("画出矩形");
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Graphics g = getGraphics();
g.setColor(Color.BLACK);
g.drawRect(50, 50, 100, 200);
}
});
jp.add(bt);
// 设置窗体的位置和大小
this.setBounds(200, 50, 800, 600);
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args) {
new RectangleFrame().setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想纯画图还是想楼上这个用某个字符打出一个矩形形状
追问
用字符打出,空心矩形、空心圆之类的。
谢谢~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询