用java如何画蘑菇代码 java简单画图板完整代码

java究竟怎么在JFrame上画东西?java在JFrame上画东西 , 主要是使用paint方法 , 代码如下:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Draw extends JFrame{
JPaneljPanel=new JPanel();
public Draw() {
jPanel.setBackground(Color.red);
add(jPanel);
Drawation drawaction=new Drawation();//添加画图,把上面jpanel的设置给覆盖了;要是先添加画图再添加
add(drawaction);//jpanel则把画图覆盖了
}
public static void main(String[] args){
Draw draw=new Draw();
draw.setTitle("abc");
draw.setSize(300,300);
draw.setVisible(true);
draw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class Drawation extends JPanel{
public void paintComponent(Graphics g){
super.paintComponents(g);
g.drawString("agagh", 50, 45);
}
}
运行结果如下:
用java 在窗体中画一个简单图形 。帮你改了一下 。
你要画在panel上,然后frame.add(panel)就能显示 。
是不是和applet搞混了 , applet复写一些方法就能显示 , 但现在你编的是java gui
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*; //import javax.swing.Timer;
import java.awt.BasicStroke;
//import java.util.Date;
//import java.text.*;
//import java.util.*;
public class TestGui {
public void paint(Graphics g) {
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度 , 3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
// frame.add(new paint(),BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setVisible(true);
Panel p = new Panel();
frame.add(p);
// frame.paint(null);
// TODO code application logic here
}
}
class Panel extends JPanel {
// 重新覆盖paint方法
public void paint(Graphics g) {
super.paint(g);
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
}
求java大佬帮忙import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Recipe {
private String name;//菜谱名称
private String style;//菜系如:川菜、湘菜等
private int time;//烹饪时长分钟
private String[] food;//食材
private String[] step;//操作步骤
public Recipe() {
}
public Recipe(String name, String style, int time, String[] food, String[] step) {
this.name = name;
this.style = style;
this.time = time;
this.food = food;
this.step = step;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public String[] getFood() {
return food;
}
public void setFood(String[] food) {
this.food = food;
}
public String[] getStep() {
return step;
}
public void setStep(String[] step) {
this.step = step;
}
@Override
public String toString() {

推荐阅读