java 无法画线为什么?高分求解答 20
以下是代码的一部分,不知道错在哪里了!就是不能显示画线publicvoidFCFS(intHeadLocation,JPanelpanel){inty=0;JLabelt...
以下是代码的一部分,不知道错在哪里了!就是不能显示画线
public void FCFS(int HeadLocation,JPanel panel)
{
int y=0;
JLabel titleLabel=new JLabel("FCFS算法");
titleLabel.setBounds(40, 0, 60, 20);
panel.add(titleLabel);
Graphics g=panel.getGraphics();
g.setColor(Color.red);
g.drawLine(10, 25, 140, 25);
import java.awt.*;
import javax.swing.*;
public class test {
public void FF(JPanel panel)
{
Graphics g=panel.getGraphics();
g.drawLine(12, 13, 55, 66);
}
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setPreferredSize(new Dimension(300,250));
JPanel primary=new JPanel(null);
primary.setBackground(Color.cyan);
JLabel l1=new JLabel();
l1.setText("wenzi");
l1.setBounds(150, 100, 50, 200);
// Graphics g=primary.getGraphics();
// g.drawLine(12, 13, 55, 66);
//frame.add(l1);
primary.add(l1);
frame.getContentPane().add(primary);
frame.pack();
frame.setLayout(null);
frame.setVisible(true);
frame.setTitle("我的第一个JAVA程序");
}
} 展开
public void FCFS(int HeadLocation,JPanel panel)
{
int y=0;
JLabel titleLabel=new JLabel("FCFS算法");
titleLabel.setBounds(40, 0, 60, 20);
panel.add(titleLabel);
Graphics g=panel.getGraphics();
g.setColor(Color.red);
g.drawLine(10, 25, 140, 25);
import java.awt.*;
import javax.swing.*;
public class test {
public void FF(JPanel panel)
{
Graphics g=panel.getGraphics();
g.drawLine(12, 13, 55, 66);
}
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setPreferredSize(new Dimension(300,250));
JPanel primary=new JPanel(null);
primary.setBackground(Color.cyan);
JLabel l1=new JLabel();
l1.setText("wenzi");
l1.setBounds(150, 100, 50, 200);
// Graphics g=primary.getGraphics();
// g.drawLine(12, 13, 55, 66);
//frame.add(l1);
primary.add(l1);
frame.getContentPane().add(primary);
frame.pack();
frame.setLayout(null);
frame.setVisible(true);
frame.setTitle("我的第一个JAVA程序");
}
} 展开
1个回答
展开全部
由于水平有限你的我看了半天找不出错来,我在你的基础上另写了个
你有时看着行你就看看,要不就另请高明吧
import java.awt.*;
import javax.swing.*;
public class Line extends JFrame{
public Line()
{
setPreferredSize(new Dimension(300,250));
pack();
PaintPanel pp= new PaintPanel();
add(pp);
setVisible(true);
setTitle("我的第一个JAVA程序");
}
public static void main(String[] args) {
new Line();
}
}
class PaintPanel extends JPanel{
JLabel l1=null;
public PaintPanel(){
setLayout(null);
l1=new JLabel();
l1.setText("wenzi");
l1.setBounds(150, 100, 50, 200);
add(l1);
}
public void paint(Graphics g) {
super.paint(g);
setBackground(Color.cyan);
g.drawLine(12, 13, 55, 66);
}
}
你有时看着行你就看看,要不就另请高明吧
import java.awt.*;
import javax.swing.*;
public class Line extends JFrame{
public Line()
{
setPreferredSize(new Dimension(300,250));
pack();
PaintPanel pp= new PaintPanel();
add(pp);
setVisible(true);
setTitle("我的第一个JAVA程序");
}
public static void main(String[] args) {
new Line();
}
}
class PaintPanel extends JPanel{
JLabel l1=null;
public PaintPanel(){
setLayout(null);
l1=new JLabel();
l1.setText("wenzi");
l1.setBounds(150, 100, 50, 200);
add(l1);
}
public void paint(Graphics g) {
super.paint(g);
setBackground(Color.cyan);
g.drawLine(12, 13, 55, 66);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询