我刚开始使用Java的GUI东西,所以我的理解并不是很好。我试图生成一个程序,用户可以拖动鼠标,并可以同时生成一个矩形。我试图这样做,但我面临着范围问题。任何意见将是有益的。我附上了我认为是我的代码的相关部分。
<form>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Name:</span>
<input type="text" class="form-control" placeholder="Ex.: John" aria-describedby="basic-addon1" id="name-input">
</div>
<div class="form-group">
<label for="sel1">Place:</label>
<select class="form-control" id="sel1" id="place-input">
<option value="1">Fixed</option>
<option value="2">Mobile</option>
</select>
</div>
<div class="form-group">
<label for="sel2">Technician:</label>
<select class="form-control" id="technician-input">
<option value="1">Brandon</option>
<option value="2">Justin</option>
<option value="3">Ryan</option>
<option value="4">Tyler</option>
</select>
</div>
</form>
}
void draw(Graphics g)
{
int canvaswidth= canvas.getWidth();
int canvasheight=canvas.getHeight();
g.setColor(new Color(0.8F, 0.8F, 0.8F));
for(int j=0;j<canvas.getHeight();j = j+10) {
g.drawLine(0,j,canvas.getWidth(),j);
}
for(int i=0;i<canvas.getWidth();i=i+10){
g.drawLine(i, 0, i,canvas.getHeight());
}
for(int k=0;k<canvas.getHeight();k=k+50){
g.setColor(new Color(0.6F, 0.6F, 0.6F));
g.drawLine(0, k, canvas.getWidth(), k);
}
for(int l=0;l<canvas.getWidth();l=l+50){
g.drawLine(l, 0, l, canvas.getHeight());
}
g.setColor(Color.red);