as_the_god as_the_god
关注数: 29 粉丝数: 13 发帖数: 943 关注贴吧数: 16
求助:用了布局之后,使用drawImage方法不显示图片 import javax.swing.*; import java.awt.*; // 引入布局管理器 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class LOTPRCTS{ public static void main(String[] args) { frame f=new frame(); } } class frame extends JFrame implements ActionListener { JLabel label=new JLabel("请输入1-100之间的整数:"); JTextField number=new JTextField(15); JButton ok=new JButton("猜"); JLabel result=new JLabel("猜测的结果"); int rand=0; JMenuItem StartItem=new JMenuItem("开始游戏"); JMenuItem StatisItem=new JMenuItem("统计"); JMenuItem EndItem=new JMenuItem("退出"); JMenu gameMenu=new JMenu("游戏"); JMenuBar bar=new JMenuBar(); int count=0; frame() { //JFrame frame = new JFrame("布局管理器"); super("布局管理器"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); panel1.setBackground(new Color(0, 255, 0)); panel2.setBackground(new Color(255, 0, 0)); panel3.setBackground(new Color(0, 0, 255)); this.add(BorderLayout.NORTH,panel1); panel1.add(new ImagePanel()); this.add(BorderLayout.CENTER,panel2); panel2.add(label); panel2.add(number); panel2.add(result); panel2.add(ok); this.add(BorderLayout.SOUTH,panel3); this.setVisible(true); } public void actionPerformed(ActionEvent e) { String s=number.getText(); int r=Integer.parseInt(s);//将s转换为整数 if(r>rand) {result.setText("你猜大了");count++;} else if(r<rand) {result.setText("你猜小了");count++;} else { result.setText("你猜对了"); rand=(int)Math.random()*100+1; } if(e.getSource()==EndItem) { System.exit(1); } else if(e.getSource()==StatisItem) { StatisDialog d=new StatisDialog(this,"统计信息",true,count); } } } class StatisDialog extends JDialog { JLabel count=new JLabel(); int c=0; StatisDialog(JFrame father,String title,boolean model,int c) { super(father,title,model); this.c=c; this.setBounds(150,240,100,80); this.add(count); count.setText(String.valueOf(c)); this.setVisible(true); } } class ImagePanel extends Canvas { ImageIcon icon=new ImageIcon("F:/Java/CFTST2/src/pics/cornerpic.jpg"); Image image=icon.getImage(); public void paint(Graphics g) { super.paint(g); if(image==null) JOptionPane.showMessageDialog(null,"kengdie"); g.drawImage(image,300,60,500,500,this); } } RT,求解
【求助】串口通信 /*------------------------------------------------ 串口中断程序 ------------------------------------------------*/ void UART_SER (void) interrupt 4 //串行中断服务程序 { unsigned int i=0; unsigned char Temp; //定义临时变量 unsigned char Temp_SensorTyple; unsigned char Temp_Data1; unsigned char Temp_Data2; unsigned char Temp_Led; if(RI) //判断是接收中断产生 { RI=0; //标志位清零 Temp=SBUF; i++; if(i==3)Temp_SensorTyple=SBUF; SBUF=Temp_SensorTyple; if(i==9)Temp_Data1=Temp; SBUF=Temp_Data1; if(i==10)Temp_Data2=Temp; SBUF=Temp_Data2; if(i==11)Temp_Led=SBUF; SBUF=Temp_Led; if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x01 && Temp_Led == 0x01 ) P0=0xfe; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x02 && Temp_Led == 0x01 ) P0=0xfd; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x03 && Temp_Led == 0x01 ) P0=0xfc; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x04 && Temp_Led == 0x01 ) P0=0xfb; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x05 && Temp_Led == 0x01 ) P0=0xfa; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x06 && Temp_Led == 0x01 ) P0=0xf9; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x07 && Temp_Led == 0x01 ) P0=0xf8; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x08 && Temp_Led == 0x01 ) P0=0xf7; else if( Temp_SensorTyple == 0x11 && Temp_Data1 == 0x00 && Temp_Data2 == 0x00 && Temp_Led == 0x01 ) P0=0xff; } if(TI) //如果是发送标志位,清零 TI=0; } 我想实现串口输入一串14byte长度的字符,获取其第3、9、10、11的字符,然后根据不同的值让不同的LED显示。但是为什么不管我输什么,每次这4个变量接收到的值都是0x00啊??
1 下一页