Senin, 19 September 2011

Tugas PBO

MINI COMPO

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace yosua_MiniCompo
{
struct Channel
{
string nam, chan;
public Channel(string nam, string chan)
{
this.nam = nam;
this.chan = chan;
}
public string Name
{
get
{
return nam;
}
set
{
nam = value;
}
}
public string Channl
{
get
{
return chan;
}
set
{
chan = value;
}
}
}

public partial class Radio : Form
{
double lowLimit = 88.0;
double hiLimit = 108.9;
double freq;
List<Channel> channelList = new List<Channel>();

Channel DJFM = new Channel(“DJ FM”, “94.8″);
Channel Istara = new Channel(“Istara”, “101.1″);
Channel Prambors = new Channel(“Prambors”, “89.3″);
Channel EBS = new Channel(“EBS”, “105.9″);
Channel Trijaya = new Channel(“Trijaya”, “104.7″);
Channel MRadio = new Channel(“M-Radio”, “98.8″);

private void AddChannel()
{
channelList.Add(DJFM);
channelList.Add(Istara);
channelList.Add(Prambors);
channelList.Add(EBS);
channelList.Add(Trijaya);
channelList.Add(MRadio);
}

private void CheckChannel()
{
channelName.Text = “”;
foreach (Channel ch in channelList)
{
if (freqBox.Text == ch.Channl)
{
channelName.Text = ch.Name;
break;
}
}
}

public Radio()
{
InitializeComponent();
freq = lowLimit;
freqBox.Text = freq.ToString(“##.##”);
AddChannel();

}

private void radioNext_Click(object sender, EventArgs e)
{
if (freq < hiLimit)
freq += 0.1;
else
freq = lowLimit;
freqBox.Text = freq.ToString(“##.##”);

}

private void freqBox_Leave(object sender, EventArgs e)
{
if (double.Parse(freqBox.Text) > hiLimit || double.Parse(freqBox.Text) < lowLimit)
{
MessageBox.Show(“Frequency exceeds the limit”,”Error”,MessageBoxButtons.OK,MessageBoxIcon.Error);
freqBox.Text = freq.ToString(“##.##”);
}
freq = double.Parse(freqBox.Text);
}

private void radioPrev_Click(object sender, EventArgs e)
{
if (freq > lowLimit)
freq -= 0.1;
else
freq = hiLimit;
freqBox.Text = freq.ToString(“##.##”);
}

private void Radio_Load(object sender, EventArgs e)
{
volBar.Value = Equalizer.Volume;
bassBar.Value = Equalizer.Bass;
trebleBar.Value = Equalizer.Treble;
}

private void volBar_Scroll(object sender, EventArgs e)
{
Equalizer.Volume = volBar.Value;
}

private void bassBar_Scroll(object sender, EventArgs e)
{
Equalizer.Bass = bassBar.Value;
}

private void trebleBar_Scroll(object sender, EventArgs e)
{
Equalizer.Treble = trebleBar.Value;
}

private void freqBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
if (double.Parse(freqBox.Text) > hiLimit || double.Parse(freqBox.Text) < lowLimit)
{
MessageBox.Show(“Frequency exceeds the limit”, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error);
freqBox.Text = freq.ToString(“##.##”);
}
freq = double.Parse(freqBox.Text);
}
}

private void freqBox_TextChanged(object sender, EventArgs e)
{
CheckChannel();
}

private void autoNext_Click(object sender, EventArgs e)
{
channelName.Text = “”;
while (channelName.Text == “” && freq < hiLimit)
{
freq += 0.1;
freqBox.Text = freq.ToString(“##.##”);
}
}

private void autoPrev_Click(object sender, EventArgs e)
{
channelName.Text = “”;
while (channelName.Text == “” && freq > lowLimit)
{
freq -= 0.1;
freqBox.Text = freq.ToString(“##.##”);
}
}
}
}

Tidak ada komentar:

Posting Komentar